WPF - Virtualizing an ItemsControl?

Posted by Rachel on Stack Overflow See other posts from Stack Overflow or by Rachel
Published on 2010-05-06T19:29:03Z Indexed on 2010/05/06 20:18 UTC
Read the original article Hit count: 524

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.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about virtualization