如何对 ObservableCollection 进行分页?
我有一个列表框,里面有太多项目,并且 UI 变得越来越慢(虚拟化已打开,等等)。 因此,我正在考虑仅显示前 20 个项目并允许用户浏览结果集(即 ObservableCollection)。
有人知道 ObservableCollection 是否存在分页机制吗? 有人以前这样做过吗?
谢谢!
I have a ListBox with way too many items in it and the UI is getting slower and slower (virtualization is on, etc). So I was thinking about displaying only the first 20 items and allow to user to navigate through the result set (i.e. ObservableCollection).
Does anybody know if a Pagination mechanism exist for the ObservableCollection? Does anybody has done that before?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此功能在 ObservableCollection 基类中不能直接使用。 您可以扩展 ObservableCollection 并创建一个自定义集合来执行此操作。 您需要将原始 Collection 隐藏在这个新类中,并根据 FromIndex 和 ToIndex 动态地将项目范围添加到该类中。 重写InsertItem 和RemoveItem。 我在下面给出了一个未经测试的版本。 但请将此视为伪代码。
更新:我在这里有一篇关于此主题的博客文章 - http://jobijoy .blogspot.com/2008/12/pagination-observablecollection.html 并将源代码上传到 Codeplex 。
This facility is not directly available in the base ObservableCollecton class. You can extend the ObservableCollection and create a custom Collection which does this. You need to hide the original Collection inside this new class and based on a FromIndex and ToIndex give dynamically add the range of items to the class. Override InsertItem and RemoveItem. I am giving a not-tested version bellow. But please take this as just pseudo code.
UPDATE: I have a blog post about this topic on here - http://jobijoy.blogspot.com/2008/12/paginated-observablecollection.html and the source code is uploaded to Codeplex.