WPF AutoCompleteBox 数据虚拟化
我正在尝试在 WPF AutoCompleteBox 上实现数据虚拟化。 我在 这里 找到了 Bea Stollnitz 的代码,它在 ListView 上运行得很好,我把它做到了可以轻松地在 ComboBox 上工作,但我似乎无法让它在 AutoCompleteBox 上正常工作。
准确地说,它是有效的 - 列表是虚拟化的,启动时项目并未全部加载 - 但似乎发生的是,一旦 ItemsSource 发生更改,AutoCompleteBox 就会迭代列表中的所有项目,这最终会破坏整个列表(即在加载时,列表中的所有页面都会被请求,因此即使它们是虚拟化的,它们也会在开始时被请求并被加载)。我的猜测是,这是因为 ACBox 进行了过滤,但令我惊讶的是,没有办法阻止它,因为该控件通常允许使用 Populate 事件在服务器端完成过滤。
我觉得我错过了一些东西,我不敢相信以前没有人做过这样的事情,或者它无法做到,所以我猜我只是做了一些我可以做的明显错误的事情。因为我是 WPF 新手,所以不明白。
以下是我为尝试将其整合在一起所做的一些事情(基于围绕类似问题的互联网搜索):
我确保内置 UI 虚拟化的所有条件都可以,包括显式打开它,设置ListBox等的最大高度
我用 ListView 替换了 AutoCompleteBox 中的 ListBox,就像 Bea 使用的 ListView 一样她的例子。并排显示,ListView 本身可以按预期工作,但嵌入到 ACBox 中的 ListView 却不能。
我尝试在 ACBox 中不使用过滤、使用自定义过滤器、手动处理填充事件等。这没有帮助。制作自定义过滤器显然是不够的,因为自定义过滤器只允许您指定评估一项的结果,循环列表的代码不可见,因此您无法阻止循环。将过滤器设置为“无”也不会执行任何操作。
欢迎任何和所有建议!
此目标是 .NET 3.5,我正在使用 WPF Toolkit(2010 年 2 月版本)
谢谢!
I am trying to implement Data Virtualization on a WPF AutoCompleteBox.
I found Bea Stollnitz's code here which works great on a ListView and I made it to work on an ComboBox easily, but there's no way I can seem to get it working right on an AutoCompleteBox.
To be precise, it works - the list is virtualized, items are not all loaded on startup - but what seems to happen is that the AutoCompleteBox iterates through all the items in the list as soon as the ItemsSource changes and this ends up breaking the whole thing (i.e. on load, all the pages in the list are requested, so even though they are virtualized, they will all be requested in the beginning and get loaded). My guess is that this is because of the filtering that the ACBox does, but I'm surprised that there's not way to prevent it, since the control does normally allow filtering to be done on the server-side using the Populating event.
I feel that I'm missing something, I can't believe that no one has done something like this before or that it can't be done, so I'm guessing that I'm just doing something obviously wrong that I can't figure out since I'm new to WPF.
Here's some of the things that I've done to try and get this together (based on Internet searches around similar problems):
I made sure all the conditions for the built-in UI virtualization are ok including explicitly turning it on, setting the max height of the ListBox etc.
I replaced the ListBox in the AutoCompleteBox with a ListView like the one that Bea uses in her example. Side by side, the ListView by itself works as expected, but the one embedded in the ACBox does not.
I tried using no filtering in the ACBox, using a custom filter, handling the populating evenet manually etc. This doesn't help. Making a custom filter is obviously not enough since the custom filter only allows you to specify the result of evaluating one item, the code that loops through the list is not visible so you can't prevent looping. Turning the filter to "None" doesn't do anything either.
Any and all suggestions are welcome!
The target for this is .NET 3.5 and I am using the WPF Toolkit (Feb 2010 release)
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将此追踪到 OnItemsSourceChanged() (请参阅源)。 AutocompleteBox 在那里存储“数据的本地缓存副本”,这就是我看到上述行为的原因。
这是一个私有方法,所以这里没有重写。
在我看来,正因为如此,您无法将 DataVirtualization 应用于 AutoCompleteBox,至少不能使用 Bea 解决方案中的想法。如果有人对此有任何不同的想法,我很乐意尝试一下,但在那之前,这就是我相信的答案。
I tracked this down to OnItemsSourceChanged() (see source). In there, the AutocompleteBox stores a "local cached copy of the data", which is why I see the behavior noted above.
This is a private method, so no overriding here.
It seems to me that because of this you can't apply DataVirtualization to the AutoCompleteBox, at least not using the ideas in Bea's solution. If anyone has any different thoughts regarding this, I would love to try it out, but until then, this is what I believe the answer to be.