I changed the control template of my ListView to look like this:
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
<ScrollViewer Background="{TemplateBinding Background}"
VerticalScrollBarVisibility="Auto"
Padding="{TemplateBinding Padding}" Style="{DynamicResource {x:Static GridView.GridViewScrollViewerStyleKey}}"
VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"
ScrollViewer.IsDeferredScrollingEnabled="True">
<StackPanel>
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<Border x:Name="FillerView" BorderThickness="0"/>
</StackPanel>
</ScrollViewer>
</Border>
The reason for this is, that I want the alternating coloration of the ListView to continue. This is done via trigger for the FillerView Border. If I remove the Stackpanel and the border Fillerview from this template my ListView is virtualizing normally and very fast. If I have it in there it is incredibly slow.
Can anyone tell my why the virtualizing does not work when I use the template above? Oh and I can not move the Border FillerView out of the Scrollviewer because I want the bottom scrollbar to be below the filler.
Thanks!
Virtualizing doesn’t work because virtualization requires that the ItemsPanel of the ItemsPresenter is measured with an actual available size. In your case you have a StackPanel as the Content of the ScrollViewer and that will be the IScrollInfo for the ScrollViewer. Now because StackPanel measures its children with infinity in the direction of the arrangement that means it will measure your ItemsPresenter with an infinite height so it would not be possible for the ItemsPanel (which would be the child of the ItemsPresenter) to know the actual available height so it could not virtualize.
I’m not sure what you mean about the alternating coloration of the listview. If you’re talking about alternating background of the items within the listview then normally one would use the AlternationConverter.