LongListSelector WP8 ItemRealized无穷大滚动列表 - (LongLi

2019-10-18 12:26发布

我想实现动态负载不定式滚动列表。 (像http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/10/01/how-to-create-an-infinite-scrollable-list-with-longlistselector.aspx )

  • 数据源是绑定到的ObservableCollection

  • 列表中的填充与添加项目到集合开始

  • ItemRealizedEvent开始的ObservableCollection的进一步馅料

我以为ItemrealizedEvent通过滚动触发,但它添加项目到集合的每个项目后始终触发。

- >因此,它不是动态的,它只是加载的一切

有任何想法吗?

在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);
            }
        }
    }
}

在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;            
    }      

Answer 1:

ItemRealized有一个交流中心的行为,但实际上它的工作原理。 它预装了一堆elementos超前的屏幕滚动的,所以如果你看到10个元素,ItemRealized预装30或40,直到您滚动到达列表的末尾之前预加载更多的项目停止。 如果你有100个单元测试它,你可以看到此行为。



文章来源: LongListSelector WP8 ItemRealized -infinite scrollable list-