WPF: TreeView virtualization not working

What can stop a TreeView from virtualizing if the TreeView is configured as follows?

<TreeView 
    ItemsSource="{Binding}" 
    VirtualizingStackPanel.IsVirtualizing="True">
    <TreeView.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel />
        </ItemsPanelTemplate>
    </TreeView.ItemsPanel>
    <TreeView.ItemContainerStyle>
        <Style
            TargetType="{x:Type TreeViewItem}">
            <Setter
                Property="IsExpanded"
                Value="{Binding IsExpanded, Mode=TwoWay}"/>
        </Style>
    </TreeView.ItemContainerStyle>
</TreeView>

I have one that is not virtualized when I expand the nodes (and use snoop to check). I have all created TreeViewItems. I am wondering if there is any combination of containers that will not allow TreeView to virtualize its content. (e.g. posting it to a StackPanel)

+5
source share
1 answer

. , , TreeView (.. DataType={x:Type TreeView} x:Key), , TreeViewItem App.xaml( ). ControlTemplate .

ItemsPanel VirtualizingStackPanel - . , TreeView . ItemsPanel VirtualizingStackPanel.Isvirtualizing="True" TreeView, TreeViewItems, TreeView , ( TreeViewItem)

+6

All Articles