question

05508434 avatar image
0 Votes"
05508434 asked ·

[WPF] UI Virtualization

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-wpfdotnet-wpf-xaml
· 1
10 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@05508434
I tested your code and reproduced your issue. Could you post your quesion on microsoft-ui-xaml where you may be assistered better.


0 Votes 0 ·

0 Answers