I'm using .NET 4.5/VS2012, and I have a ListView looks something like this
<ListView
VirtualizingPanel.IsContainerVirtualizable="True"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
Grid.Row="1"
Name="eventLogList"
Margin="5,0,5,0"
BorderBrush="Black"
BorderThickness="2"
ItemsSource="{Binding EventLogs}"
SelectedItem="{Binding SelectedEventLog}"
local:ListViewSorter.CustomListViewSorter="EventLogViewer.UI.EventLogItemComparer"
SelectionMode="Single">
<ListView.GroupStyle>
<GroupStyle HidesIfEmpty="False">
<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<Expander IsExpanded="True">
<Expander.Header>
<TextBlock FontSize="20" TextWrapping="Wrap" Margin="0,10,0,5" >
<Bold><TextBlock Text="{Binding Name}"/></Bold> - <TextBlock FontSize="20" Text="{Binding ItemCount}"/> logs
</TextBlock>
</Expander.Header>
<ItemsPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
<ListView.View>
<GridView>
<GridViewColumn
Header="event id"
Width="120"
DisplayMemberBinding="{Binding EventID}" />
<GridViewColumn
Header="level"
Width="160"
DisplayMemberBinding="{Binding Level}" />
<GridViewColumn
Header="server"
Width="160"
DisplayMemberBinding="{Binding Server}" />
<GridViewColumn
Header="log name"
Width="160"
DisplayMemberBinding="{Binding LogName}" />
<GridViewColumn
Header="source"
Width="240"
DisplayMemberBinding="{Binding Source}" />
<GridViewColumn
Header="logged"
Width="240"
DisplayMemberBinding="{Binding Logged}" />
</GridView>
</ListView.View>
</ListView>
But still the performance is not improving at all. I found an example using ListBox, but how to virtualize a ListView? I struggled quite a bit.
I heard that with grouping, the virtualization is turned off in previous version of WPF, but with .NET 4.5, WPF has a IsVirtualizingWhenGrouping
property, I already set it to True
.
Update: The culprit is custom styling, after removing it, the list view runs smoothly like butter
This article will help you a lot.Also can see..
"UI virtualization stores only visible items in memory but in a data-binding scenario stores the entire data structure in memory. In contrast, data virtualization stores only the data items that are visible on the screen in memory."
"By default, UI virtualization is enabled for the ListView and ListBox controls when their list items are bound to data."
For more info view the original MSDN source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With