Windows Phone 8 Long List Selector - scroll to bottom after data loaded async

你离开我真会死。 提交于 2019-12-04 19:39:08

Maybe this will work:

private async Task DoAndScroll()
{
   await App.MessagesViewModel.LoadData();
   var lastMessage = App.MessagesViewModel.Messages.LastOrDefault();
   llsMessages.ScrollTo(lastMessage);
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
   string contactId = "";
   if (NavigationContext.QueryString.TryGetValue("contactId", out contactId))
   {
      DataContext = App.MessagesViewModel;  
      DoAndScroll();     
   }
}

Try the ItemRealized event of the longlistselector. Check whether the currently processed item in the selector is the last item of your datacontext and if it is so, then scroll to that item. Below code worked for me.

private void longlist_ItemRealized(object sender, ItemRealizationEventArgs e)
    {
        Search.BindSearch search = e.Container.Content as Search.BindSearch;
        if (search != null)
        {
            int offset = 0;

            if (OCollectionBindSearch.Count - OCollectionBindSearch.IndexOf(search) <= offset)
            {
                longlist.ScrollTo(search);
            }                
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!