列表框未虚拟化 [英] ListBox not Virtualizing

查看:80
本文介绍了列表框未虚拟化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个没有虚拟化的ListBox.我显然缺少了一些东西,但找不到它.

它实际上是一个ListBox中的一个ListBox.外部列表框具有一个包含扩展器的ItemTemplate.扩展器用于显示一组项目. Expander的内容是第二个显示项目的ListBox.第二个ListBox上的ItemTemplate绑定到要显示的实际Item.我的商品的ViewModel类具有许多属性,这些属性在调用属性Get之前不会初始化数据.但是,WPF遍历了每一项并引起了初始化逻辑,这是我试图避免的.

我发现使用ListCollectionView.GroupDescription会导致ListBox无法虚拟化.现在,我在ViewModel中处理自己的分组.我的外部ListBox绑定到ObservableCollection(ItemGroupViewModel),其中ItemGroupViewModel具有GroupName和项目列表.第二个ListBox绑定到ItemGroupViewModel中的Items.这不能解决问题.我还在调试时检查了VirtualizingStackPanel.GetIsVirtualizing(),它返回true,但是WPF仍在遍历所有项目.我已仔细检查以确保我的分组逻辑不会触发每个项目中的数据初始化逻辑,这是我要避免的事情.

我认为IsSharedSizeScope可能导致ListBox呈现所有项目,以便确定列的大小.所以我关闭了SharedSizeScope.仍然没有虚拟化.

我想念什么?

解决方案

它不是虚拟化的,因为它位于扩展器内部,扩展器的模板是headeredcontentcontrol(据我所记得),并且它的模板包含一个stackpanel./p>

stackpanel的内容永远不会沿其堆叠方向延伸,因此您的列表框将始终具有它要求的所有空间,因此您将无法获得任何虚拟化.您内部的列表框也不会显示任何垂直滚动条.

您有一个解决方案(至少:)

1:在内部列表框中设置maxheight-可能是最简单的.

希望它会有所帮助:)

I have a ListBox which is not virtualizing. I am obviously missing something, but cannot find it.

It's actually a ListBox within a ListBox. The outer ListBox has an ItemTemplate which contains an Expander. The Expander is used to display a group of items. The content of the Expander is the second ListBox which displays the items. The ItemTemplate on the second ListBox is bound to the actual Item to display. The ViewModel class for my items has a number of properties which do not initialize data until the property Get is called. However, WPF is walking through every item and causing initialization logic, which I'm trying to avoid.

I discovered that using the ListCollectionView.GroupDescription causes a ListBox to not Virtualize. Now I am handling my own grouping in the ViewModel. My outer ListBox is bound to an ObservableCollection(ItemGroupViewModel), where ItemGroupViewModel has a GroupName and a list of Items. The second ListBox is bound to the Items in the ItemGroupViewModel. This did not fix the problem. I also checked VirtualizingStackPanel.GetIsVirtualizing() while debugging and it returns true, but WPF is still walking through every item. I've double checked to ensure my grouping logic does not fire off the data initialization logic in each item, which I'm trying to avoid.

I thought the IsSharedSizeScope could cause the ListBox to render all items in order to determine column sizing. So I turned SharedSizeScope off. Still no virtualization.

What am I missing?

解决方案

It is not virtualizing because it is inside an expander, the expander's template is a headeredcontentcontrol (as far as I remember), and it's template contains a stackpanel.

Contents of stackpanel can never have alignement stretch in the direction it is stacking, so your listbox will always have all the room it asks for, and then you get no virtualization. Your inner listbox won't get any verticalscrollbar either.

You have one solution (at least :)

1: Set maxheight on your inner listbox - probably the easiest.

Hope it helps :)

这篇关于列表框未虚拟化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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