使用 LongListSelector 进行连续分页 [英] Continuous Pagination with LongListSelector

查看:29
本文介绍了使用 LongListSelector 进行连续分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的 LongListSelector 滚动到底部时,我想从 Web 服务自动加载更多数据.就像商店应用程序一样.我的问题是我找不到任何触发加载更多操作的事件.

When my LongListSelector is scrolled to bottom, I want to automatically load more data from a web service. Just like the Store app does. My problem is that I can't found any event to trigger the load more action.

推荐答案

Microsoft 的建议是使用 LongListSelector.ItemRealized 事件,检查它是否是列表中的最后一项(或第 N 个最后一项)要实现""如果是,那么它将开始获取新记录.在 UX 方面,当时最好在 SystemTray 上显示一个 ProgressIndicator,而不是尝试用内联微调器模仿 iOS.

The recommandation from Microsoft is to use the LongListSelector.ItemRealized event, check if it's the last item (or the Nth last item) in the list to be "realized" and if it is, then it will start fetching new records. In terms of UX, it's best to show a ProgressIndicator on the SystemTray at the time and not try to imitate iOS with inline spinners.

LongListSelector.ItemRealized 实际上是一个非常有趣的事件,因为它会在 Item 数据绑定到虚拟化 ListBoxItem 时触发.这意味着 LongListSelector 虚拟化逻辑认为它需要准备要在屏幕上显示的 FrameworkElement.ListBoxItem 可能还没有出现在屏幕上,但这是一个很好的迹象,它正在到达那里.

LongListSelector.ItemRealized is actually a very interesting event since it fires when an Item has been data bound to a virtualized ListBoxItem. That means that the LongListSelector virtualization logic thinks it needs to prepare the FrameworkElement to be shown on screen. The ListBoxItem may or may not be on screen yet, but it's a good indication it's getting there.

有关代码示例,请参阅@http://code.msdn.microsoft.com/wpapps/TwitterSearch-Windows-b7fc4e5e

For a code sample see @ http://code.msdn.microsoft.com/wpapps/TwitterSearch-Windows-b7fc4e5e

    void resultListBox_ItemRealized(object sender, ItemRealizationEventArgs e)
    {
        if (!_viewModel.IsLoading && resultListBox.ItemsSource != null && resultListBox.ItemsSource.Count >= _offsetKnob)
        {
            if (e.ItemKind == LongListSelectorItemKind.Item)
            {
                if ((e.Container.Content as TwitterSearchResult).Equals(resultListBox.ItemsSource[resultListBox.ItemsSource.Count - _offsetKnob]))
                {
                    Debug.WriteLine("Searching for {0}", _pageNumber);
                    _viewModel.LoadPage(_searchTerm, _pageNumber++);
                }
            }
        }
    }

这篇关于使用 LongListSelector 进行连续分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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