WPF - Virtualizing an ItemsControl?
- by Rachel
I have an ItemsControl containing a list of data that I would like to virtualize, however VirtualizingStackPanel.IsVirtualizing="True" does not seem to work with an ItemsControl.
Is this really the case or is there another way of doing this that I am not aware of?
To test I have been using the following block of code:
<ItemsControl
VirtualizingStackPanel.IsVirtualizing="True"
ItemsSource="{Binding Path=AccountViews.Tables[0]}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Initialized="TextBlock_Initialized"
Margin="5,50,5,50" Text="{Binding Path=Name}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
If I change the ItemsControl to a ListBox, I can see that the Initialized function only runs a handful of times (the huge margins are just so I only have to go through a few records), however as an ItemsControl every item gets initialized. I have tried setting the ItemsControlPanelTemplate to a VirtualizingStackPanel but that doesn't seem to help.