需要使用虚拟化和按需加载的WPF TreeView搜索示例 [英] Need a sample for WPF TreeView search with Virtualization and Load On Demand
问题描述
我需要在WPF TreeView
中实现搜索功能(基本上,我需要记住上次的用户选择).我尝试了各种建议的方法,但是由于TreeView
在我的TreeView
中启用了,所以没有任何效果,并且只有在扩展父节点时才加载子节点(延迟加载).
I need to implement search feature in WPF TreeView
(basically I need to remember the last user selection). I have tried various approaches suggested but nothing works as virtualization
is enabled in my TreeView
and child nodes are loaded only when a parent node is expanded(lazy loading).
任何人都知道一个示例将这三个要素(虚拟化,按需加载和搜索)实现在一起吗?
Anyone knows of a sample having these three things(Virtualization, Load-on-demand and Search) implemented together?
推荐答案
Have a look at this MSDN forum thread, Bob from MS explains the problem in implementing this feature.
原因是
VirtualizingStackPanel
尝试生成 一个要显示的项目,但是有一个 发电机已经在您的项目中 生成展开的项目(在OnTreeNodeExpanded
事件处理程序).它 与两个生成器发生冲突.VirtualizingStackPanel
可以生成 在运行时需要的项目,它也 在BringIndexIntoView
中生成它们 方法.StartAt
方法的代码 是检查发电机,如果不是 null,则抛出异常无法调用StartAt
在进行内容生成时 进度".因此,样本将填充 绑定源中的所有项目InitializeComponent()
,然后让BringIndexIntoView
方法生成 项目的容器.
the cause is the
VirtualizingStackPanel
try to generate a item for display, but it has a generator already in your project to generate the expanded items (in theOnTreeNodeExpanded
event handler). It occurs conflict with two generators.VirtualizingStackPanel
can generate the required item at run-time, it also generate them inBringIndexIntoView
method. The code of theStartAt
method is to check the generator, if it isn't null, throw the exception "Cannot callStartAt
when content generation is in progress". So, the sample populates all items to the bound source in theInitializeComponent()
, and let theBringIndexIntoView
method to generates the container for the item.
一个再现该问题的示例也附在该线程中.
A sample reproducing the problem is also attached in that thread.
所以目前看来,这种方法尚无解决方法:(
So at present there seems to be no solution for this approach :(
这篇关于需要使用虚拟化和按需加载的WPF TreeView搜索示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!