I have a ListBox that 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?