开发者

Is there a way to enable container recycling when grouping in a ListBox?

开发者 https://www.devze.com 2023-04-03 06:05 出处:网络
I have a ListBox t开发者_JAVA百科hat can contain hundreds of items. I\'ve added the following attributes to the listbox and performance is great, even if I group / ungroup (using x as ListCollectionVi

I have a ListBox t开发者_JAVA百科hat can contain hundreds of items. I've added the following attributes to the listbox and performance is great, even if I group / ungroup (using x as ListCollectionView)

<ListBox ItemsSource="{Binding x}"
        VirtualizingStackPanel.IsVirtualizing="True"
        VirtualizingStackPanel.VirtualizationMode="Recycling"/>

However, if I set the ListBox.GroupStyle to anything, even the most simple thing possible, it takes a few seconds to switch from grouped -> ungrouped.

<ListBox.GroupStyle>
    <GroupStyle>
        <GroupStyle.ContainerStyle>
            <Style TargetType="GroupItem">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <ItemsPresenter/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>
</ListBox.GroupStyle>

I think the reason for this is that WPF is throwing away the cache of containers (enabled by recycling mode in the VirtualizingStackPanel) when I switch to ungrouped and is having to rebuild them from scratch.

Is there a way to improve the performance here? Can anyone suggest something I could try or perhaps a resource I could check out?


Check this post, maybe it will be helpful

WPF: Data Virtualization

Also I found similar question on stackoverflow: WPF ListView Virtualization Grouping

and another one (even with answer) WPF Data virtualizing ListView

0

精彩评论

暂无评论...
验证码 换一张
取 消