WPF TreeView virtualization breaks as soon as anything is added to the window
Virtualization works when the TreeView is the only thing in the Window. For example:
<Grid>
<vw:FontTreeView x:Name="fontTreeViewControl" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" BorderThickness="0" />
</Grid>
But even simply adding row definitions breaks the virtualization entirely:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<vw:FontTreeView x:Name="fontTreeViewControl" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" BorderThickness="0" />
</Grid>
My TreeViewItem style has the following trigger:
<Style.Triggers>
<Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
开发者_运维百科 <VirtualizingStackPanel/>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
And of course the TreeView has VirtualizingStackPanel.IsVirtualizing="True"
Q. How can I have other elements in my window without breaking the virtualization? Thank you help is much appreciated.
My problem was with setting the Height to Auto. It must either be fixed, or use a * instead. In my instance in RowDefinition.
精彩评论