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 ItemsSource="{Binding Path=AccountViews.Tables[0]}"
VirtualizingStackPanel.IsVirtualizing="True">
<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
event 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.