Share via

[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?

Developer technologies | Windows Presentation Foundation
Developer technologies | XAML
Developer technologies | 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.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.