需要使用虚拟化和按需加载的WPF TreeView搜索示例 [英] Need a sample for WPF TreeView search with Virtualization and Load On Demand

查看:346
本文介绍了需要使用虚拟化和按需加载的WPF TreeView搜索示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在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 the OnTreeNodeExpanded event handler). It occurs conflict with two generators. VirtualizingStackPanel can generate the required item at run-time, it also generate them in BringIndexIntoView method. The code of the StartAt method is to check the generator, if it isn't null, throw the exception "Cannot call StartAt when content generation is in progress". So, the sample populates all items to the bound source in the InitializeComponent(), and let the BringIndexIntoView 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屋!

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