Override VirtualizationMode default value on TreeViewItems

88 views Asked by At

I want the default value of VirtualizingPanel.VirtualizationMode to Recycling, mainly on TreeViewItems. It may be something simple I'm missing but I've tried all these:

<TreeView VirtualizingPanel.IsVirtualizing="True"
          VirtualizingPanel.CacheLengthUnit="Pixel"
          VirtualizingPanel.VirtualizationMode="Recycling"/>

<Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
    <Setter Property="VirtualizingPanel.VirtualizationMode" Value="Recycling" />
</Style>
static MainWindow()
{
    VirtualizingPanel.VirtualizationModeProperty.OverrideMetadata(
        typeof(VirtualizingPanel), new FrameworkPropertyMetadata(VirtualizationMode.Recycling));
    VirtualizingPanel.VirtualizationModeProperty.OverrideMetadata(
        typeof(MainWindow), new FrameworkPropertyMetadata(VirtualizationMode.Recycling));
    VirtualizingPanel.VirtualizationModeProperty.OverrideMetadata(
        typeof(TreeViewItem), new FrameworkPropertyMetadata(VirtualizationMode.Recycling));
    VirtualizingPanel.VirtualizationModeProperty.OverrideMetadata(
        typeof(VirtualizingStackPanel), new FrameworkPropertyMetadata(VirtualizationMode.Recycling));
}

But it all seems to do nothing. According to the Xaml live property explorer. enter image description here

How to reproduce:

  • Download and run the source code from github in Visual Studio in debug mode.
  • Open the "Live Visual Tree" window in Visual Studio and find a VirtualizingStackPanel under some TreeViewItem.
  • Right-click, select properties, and find the VirualizationMode property.
0

There are 0 answers