WPF ListBox中生成项目,如用户滚动 [英] WPF ListBox generate items as user scrolls

查看:133
本文介绍了WPF ListBox中生成项目,如用户滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个列表框来显示选项,一个用户可能是无限的名单。目前,我只是切断了列表中的任意一点,但我想允许用户向下滚动,只要他们想要的。另外,我希望避免产生不可见的物品尽可能作为一些计算有工作要做,以生成每个项目

I am trying to use a ListBox to display a possibly infinite list of options to a user. Currently, I am simply cutting off the list at an arbitrary point, but I would like to allow the user to scroll down as far as they want. Also, I want to avoid generating non-visible items as much as possible as some computation has to be done to generate each item.

我试着写 listBox.ItemsSource =枚举期待它仅要求枚举可见的物品,而是它会尝试读取所有的这会导致一个无限循环的项目如果有无穷多个项目。

I tried writing listBox.ItemsSource = enumerable expecting it to only ask the enumerable for visible items, but instead it tries to read all of the items which causes an infinite loop if there are infinitely many items.

我的最好的办法是补充,得到通知的侦听器,只要列表框向下滚动,并增加新的项目,例如,总是有 K 可见的最后一个项目之后,更多的项目(其中 K 可能是在同一时间,以便向下翻页作品可见项目的数量)。

My best idea is add a listener that gets notified whenever the ListBox scrolls down and add new items such that there are always k more items after the last item visible (where k is probably the number of items visible at a time so Page Down works).

有一些清洁的方式来处理呢?

Is there some cleaner way to handle this?

推荐答案

我会用一个 VirtualizingStackPanel 来使用户界面绘制较少的元素,然后使用数据虚拟化技术限制要保持在内存中的数据。查看更多详细信息<一个href="http://stackoverflow.com/questions/1389769/wpf-virtualizingstackpanel-for-increased-performance">here (特别是比亚Stolnitz的博客文章在这里引用)。

I would use a VirtualizingStackPanel to make the UI draw fewer elements and then employ a Data Virtualization technique to limit the data you are keeping in memory. See more details here (especially Bea Stolnitz's blog entries referenced here).

这篇关于WPF ListBox中生成项目,如用户滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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