使用 LongListSelector 进行连续分页

编程入门 行业动态 更新时间:2024-10-23 06:30:43
本文介绍了使用 LongListSelector 进行连续分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

当我的 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/wpapps/TwitterSearch-Windows-b7fc4e5e

For a code sample see @ http://code.msdn.microsoft/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 14:06:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117529.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   LongListSelector

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!