使用LongListSelector进行连续分页

Tom*_*rez 6 windows-phone-8

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

Jus*_*gel 13

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

LongListSelector.ItemRealized实际上是一个非常有趣的事件,因为当Item已经绑定到虚拟化ListBoxItem的数据时它会触发.这意味着LongListSelector虚拟化逻辑认为它需要准备要在屏幕上显示的FrameworkElement.ListBoxItem可能在屏幕上,也可能不在屏幕上,但这是一个很好的迹象表明它已经到了.

有关代码示例,请参阅@ 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++);
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)