我需要在 WPF 中实现搜索功能 TreeView
(基本上我需要记住上次用户选择)。我尝试了各种建议的方法,但没有任何效果如 virtualization
在我的 TreeView
中启用和子节点仅在父节点展开时加载(延迟加载)。
任何人都知道将这三件事(虚拟化、按需加载和搜索)一起实现的示例吗?
最佳答案
看看this MSDN 论坛帖子,来自 MS 的 Bob 解释了实现此功能的问题。
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.
该线程中还附有重现该问题的示例。
所以目前这种方法似乎没有解决方案:(
关于wpf - 需要一个带有虚拟化和按需加载的 WPF TreeView 搜索示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3715583/