LongListSelector WP8 ItemRealized-无限滚动列表- [英] LongListSelector WP8 ItemRealized -infinite scrollable list-

查看:273
本文介绍了LongListSelector WP8 ItemRealized-无限滚动列表-的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个带有动态负载的不定式可滚动列表. (例如

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 )

  • 数据源已绑定到ObservableCollection

  • The DataSource is bound to a ObservableCollection

列表的填充首先是将项目添加到集合中

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

ItemRealizedEvent 开始进一步填充ObservableCollection

The ItemRealizedEvent starts further fillings of the ObservableCollection

我认为ItemrealizedEvent是由 scrolling 触发的,但是它总是在将项目添加到每个项目的集合后触发.

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

有什么想法吗?

在PageClass中:

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

在ViewModelClass内:

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

推荐答案

ItemRealized具有某种行为,但实际上可以.它在屏幕滚动之前预加载了一堆elementos,因此,如果您看到10个元素,则ItemRealized预加载30或40,然后停下来,直到滚动滚动以预加载更多项目,然后到达列表的末尾.如果用100个元素对其进行测试,您将看到此行为.

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.

这篇关于LongListSelector WP8 ItemRealized-无限滚动列表-的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆