[WPF] UI Virtualization

나래 정 1 Reputation point
2021-04-21T04:57:30.78+00:00

I decided to use UI virtualization, because there are a lot of items in the treeview.
so I did like this,

 <TreeView x:Name="mainTree"
                       VirtualizingStackPanel.IsVirtualizing="True" 
                       VirtualizingStackPanel.VirtualizationMode="Recycling"
                       ItemsSource="{Binding RootCollView}"
                       Template="{DynamicResource TreeViewMultiSelectTreeViewControlTemplate1}"
                       ItemContainerStyle="{DynamicResource TreeViewItemStyle1}" >
                         <TreeView.ItemTemplate>
                             <HierarchicalDataTemplate ItemsSource="{Binding ListCollView}">  
                                 <local:CustomCtrl />  
                             </HierarchicalDataTemplate>  
                         </TreeView.ItemTemplate>  
     </TreeView>


         <ControlTemplate x:Key="TreeViewMultiSelectTreeViewControlTemplate1" TargetType="{x:Type TreeView}">
             <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
                 <ScrollViewer x:Name="scrollViewer" CanContentScroll="True" Focusable="False" 
                               HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" 
                               Padding="{TemplateBinding Padding}" 
                               SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                               VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" 
                               Template="{DynamicResource TreeViewScrollViewerControlTemplate}">
                     <ScrollViewer.Resources>
                         <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
                             <Setter Property="UseLayoutRounding" Value="True"/>
                         </Style>
                     </ScrollViewer.Resources>
                     <!--<ItemsPresenter x:Name="content"/>-->
                     <Grid Margin="0,0,0,1">
                         <ItemsPresenter x:Name="content"/>
                         <Canvas>
                             <Border x:Name="selectionBorder" BorderThickness="1" HorizontalAlignment="Left" Visibility="Collapsed" VerticalAlignment="Top"
                                     BorderBrush="#FFAB34CC" 
                                     Background="#FFAB11AB"/>
                         </Canvas>
                     </Grid>
                 </ScrollViewer>
             </Border>
         </ControlTemplate>

However, every time i expand the treeview item, it takes a very long time. Removing the grid control from the ControlTemplate's scrollviewer doesn't take long.
Please let me know what is the root cause.
It takes too long.
And, what can I do to avoid this kind of time delay?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,681 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
767 questions
{count} votes