列表框数据虚拟化和多选
我有一个列表框,可能包含大量带有支持数据的项目。为了处理数据虚拟化,我通过编写一个集合来绑定到 WPF 的 UI 虚拟化,该集合实现与 ObservableCollection 相同的接口,并且可以根据需要启动我们的支持数据。
这很好用。当我使用列表框引入多选时,问题就出现了。由于列表框通过对象而不是索引(SelectedItems)管理所选项目,因此选择所有项目会导致所有后备数据被列表框旋转并保存在内存中,从而破坏数据虚拟化......
有没有办法防止除了重写 ListBox 以通过索引而不是对象管理选择之外,还会发生这种情况吗?
谢谢!
埃里克
I have a listbox that can potentially have a large number of items with backing data. In order to handle data virtualization, I have tied into WPF's UI virtualization by writing a collection that implements the same interfaces as ObservableCollection and can spin up our backing data as needed.
This works fine. The problem comes when I introduce multi-select with the listbox. Because listbox manages selected items by object rather than index (SelectedItems), selecting all of the items causes all of the backing data to be spun up and held in memory by the listbox, defeating the data virtualization...
Is there a way to prevent this from happening other than re-writing ListBox to manage selection by index instead of object?
Thanks!
Eric
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不在 UI 控件上使用虚拟化选项?这只会加载要在屏幕上显示的数据。
http://www.kirupa.com/net/ui_virtualization_pg1.htm
Why don't you use the Virtualizing option on the UI control? This will only load the data that is to be displayed on the screen.
http://www.kirupa.com/net/ui_virtualization_pg1.htm
我们使用 UI 虚拟化来控制数据虚拟化,但在列表框保持选择时遇到问题,因此我们的数据没有被卸载。
我最终所做的是将虚拟化堆栈面板的项目生成器绑定到一起,并监听生成的容器的数据上下文更改事件。发生这种情况时,我要么从包装器中卸载真实数据。
We were using UI virtualization to control our data virtualization, but were having problems with listbox holding onto selection, so our data was not being unloaded.
What I ended up doing was tieing into the item generator for the virtualizing stack panel and listening to the data context changed event for the generated containers. When this happened, I either unloaded the real data from our wrapper.