WPF : TreeView virtualization not working
The problem was with the styling. After some research we found that there was an unnamed style targeting the TreeView (i.e. one with DataType={x:Type TreeView}
without an x:Key
) and one targetting the TreeViewItem
in our App.xaml (or equivalent) It was overriding the ControlTemplate
for each respectively.
These styles did not have the triggers to set the ItemsPanel
to a VirtualizingStackPanel
and had no mention of any virtualization. When the styles are removed the TreeView works fine. Even though the local properties set the ItemsPanel
and the VirtualizingStackPanel.Isvirtualizing="True"
on the TreeView
these properties were not being propogated to the TreeViewItems
so the top level of the TreeView would virtualize whilst the sub categories would not (as their virtualization behaviour was dependant on the TreeViewItem
)