Tree virtualization and erratic scrolling

I have a WPF tree with a lot of nested data, I turned on virtualization, which works in terms of loadable data. But scrolling became unstable until the whole view scrolls once, and then it pays off for some (not yet large) ones. I override ScrollViewer and I see that the Height in VirtualizingStackPanel changes with error while scrolling.

Does anyone know how to resolve this?

Any help is appreciated.

The relevant sections of TreeView Xaml are below:

<TreeView ItemsSource="{Binding Folders.ObservableTree}" Name="FoldersTreeView" AutomationProperties.AutomationId="foldersview_treeview_folders" TabIndex="0" PreviewMouseRightButtonDown="OnPreviewMouseRightButtonDown" VirtualizingStackPanel.CleanUpVirtualizedItem="VirtualizingStackPanel_OnCleanUpVirtualizedItem" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.IsDeferredScrollingEnabled ="True" VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" VirtualizingStackPanel.ScrollUnit="Pixel" VirtualizingStackPanel.VirtualizationMode="Standard" VirtualizingPanel.IsVirtualizingWhenGrouping="True" VirtualizingStackPanel.CacheLengthUnit="Item"> <TreeView.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel IsItemsHost="True" CanVerticallyScroll="True"/> </ItemsPanelTemplate> </TreeView.ItemsPanel> <TreeView.Template> <ControlTemplate> <view:ScrollViewer2 Padding="{TemplateBinding Control.Padding}" Focusable="False" Name="TreeViewScrollViewer" CanContentScroll="True"> <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> </view:ScrollViewer2> </ControlTemplate> </TreeView.Template> 
+7
wpf scrollbar treeview
source share
1 answer

Virtualization works well if all items in ItemsPresenter (and TreeView implemented as ItemsPresenter with nested ItemsPresenters ) are the same height. With TreeView this is usually not the case.

The main reason for this is that, since it is virtualized, it must evaluate certain things that it would otherwise accurately determine:

VirtualizationStackPanel will assume that all children are the same height as the currently visible children, and will evaluate the desired height based on this (instead of actually measuring all children) reported by ScrollViewer , if the children have a variable height, this estimate may be disabled and will change depending on the scroll position, which will result in a constantly changing scrollbar width.

0
source share

All Articles