优化包含数千个项目的 WPF ComboBox 搜索
我有一个 WPF ComboBox 控件,其 itemsSource 包含 66000 个项目。为了提高加载性能,我使用了 VirtualizingStackPanel,它没问题,但现在我遇到了另一个问题。
ComboBox 是可编辑的,当我在 TextBox 上键入时,它开始搜索要匹配的 SelectedItem...但它很慢并且不会立即响应键入的字符。
如何避免这种行为?
I have a WPF ComboBox control with an itemsSource of 66000 items. To improve loading performance I've used VirtualizingStackPanel and it's ok but now I've another problem.
The ComboBox is editable and when I type on TextBox it start search for SelectedItem to match...but it is slow and don't immediately respond to character typed.
How can avoid this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Bruno 基本上说的是:
在 msdn 上阅读更多相关信息:
http://msdn.microsoft.com/en-us /library/system.windows.controls.virtualizingstackpanel.aspx
这是代码请注意,您需要添加其他绑定...:
或者您可以手动将其添加...
What Bruno basically said:
Read up on msdn more about it:
http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.aspx
Here's the code Note you'll need to add in your other bindings... :
Or you can manually add it in ...
使用 VirtualizingStackPanel 仅确保您拥有UI 虚拟化,但就您的情况而言,正如 BoltClock 可能想指出的那样,您可能还需要考虑实现DataVirtualization...
Using VirtualizingStackPanel only ensure that you will have UI Vitualization but in your case, as BoltClock probably wanted to point out, you might need to consider implementing DataVirtualization as well...
使用 VirtualizingStackPanel.VirtualizationMode="Recycling"
这将重用项目容器,而不是创建和丢弃项目容器并提高性能。
Use
VirtualizingStackPanel.VirtualizationMode="Recycling"
this will reuse the item containers instead create and discard the item containers and improve performance.