LongListSelector WP8 ItemRealized -infinite scrollable list-

我们两清 提交于 2019-12-13 17:44:10

问题


I am trying to implement a infinitive scrollable List with dynamic load. (like http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/10/01/how-to-create-an-infinite-scrollable-list-with-longlistselector.aspx )

  • The DataSource is bound to a ObservableCollection

  • The filling of the list starts with adding items to the collection

  • The ItemRealizedEvent starts further fillings of the ObservableCollection

I thought the ItemrealizedEvent is triggered by scrolling BUT it triggers always after adding items to the collection for each item.

--> So its not dynamic, it just loads everything

any Ideas?

Within PageClass:

within the Constructor:
(...)
LLS_BooksListAll.DataContext = _viewModel.SearchAllViewModel;
LLS_BooksListAll.ItemsSource = _viewModel.SearchAllViewModel.MediumCollection;
(...)

private async void LLS_BooksListAll_ItemRealized(object sender, ItemRealizationEventArgs e)
{
    if ((LLS_BooksListAll.ItemsSource as ObservableCollection<Medium>) == null) return;

    //get number of loaded items
    int currentItemsCount = (LLS_BooksListAll.ItemsSource as ObservableCollection<Medium>).Count;

    if (!_viewModel.SearchAllViewModel.IsLoading && currentItemsCount >= _offsetKnob &&
        (e.Container.Content as Medium) != null)
    {
        if ((e.Container.Content as Medium).Equals((LLS_BooksListAll.ItemsSource as
            ObservableCollection<Medium>)[currentItemsCount - _offsetKnob]))
        {
            _pageNumberAll++;
            try
            {
                await _viewModel.SearchAllViewModel.SearchAll(TB_Search.Text, _pageNumberAll);
            }
            catch (RestException ex)
            {
                MessageBox.Show("Connection-Error:  LLS_BooksListAll_ItemRealized - " + ex.Message);
            }
        }
    }
}

Within ViewModelClass:

    public async void SearchAll(string searchword, int pageNumber)
    {
        if (pageNumber == 1) this.MediumCollection.Clear();
        IsLoading = true;
        SearchRequest search = new SearchRequest();
        String responseString = await search.Get(searchword, SearchRange.all, pageNumber);
        MediaUser response = JsonConvert.DeserializeObject<MediaUser>(responseString);
        foreach (Medium med in response.media)
        {
            MediumCollection.Add(med); //Filling the observable collection
        }
        IsLoading = false;            
    }      

回答1:


ItemRealized have an extrange behavior but actually it Works. It preload a bunch of elementos ahead of the screen scroll so if you are seeing 10 elements, ItemRealized preload 30 or 40 and the stop until you scroll to preload more items before you reach the end of the list. If you test it with 100 elements you could see this behavior.



来源:https://stackoverflow.com/questions/18352217/longlistselector-wp8-itemrealized-infinite-scrollable-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!