wpf - 在对虚拟化 ListView 进行分组时,如何避免 VirtualizingStackPanel.MeasureOverride 卡住?

标签 wpf ui-virtualization

当 ListView 被分组并且

                      ScrollViewer.CanContentScroll="True"
                      ScrollViewer.VerticalScrollBarVisibility="Visible"
                      VirtualizingPanel.IsVirtualizing="True"
                      VirtualizingPanel.IsVirtualizingWhenGrouping="True"
                      VirtualizingPanel.VirtualizationMode="Recycling">

(只有上面的 IsVirtualizingWhenGrouping="True"会导致卡住)

向下滚动会导致整个程序卡住。它永远不会再次活跃。在 VS2015 中中断时,调用堆栈如下所示:
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(System.Windows.Size constraint, ref double? lastPageSafeOffset, ref System.Collections.Generic.List<double> previouslyMeasuredOffsets, ref double? lastPagePixelSize, bool remeasure) + 0x3408 bytes   
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(System.Windows.Size constraint) + 0xda bytes   
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x533 bytes  
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x25d bytes  
PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement element, System.Windows.Size constraint) + 0x48 bytes   
PresentationFramework.dll!System.Windows.Controls.ItemsPresenter.MeasureOverride(System.Windows.Size constraint) + 0x13 bytes   
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x533 bytes  
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x25d bytes  
PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement element, System.Windows.Size constraint) + 0x48 bytes   
PresentationFramework.dll!System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size constraint) + 0x13 bytes 
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x533 bytes  
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x25d bytes  
PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint) + 0x2d2 bytes  
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x533 bytes  
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x25d bytes  
PresentationFramework.dll!System.Windows.Controls.DockPanel.MeasureOverride(System.Windows.Size constraint) + 0x102 bytes   
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x533 bytes  
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x25d bytes  
PresentationFramework.dll!System.Windows.Controls.Control.MeasureOverride(System.Windows.Size constraint) + 0x5e bytes  
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x533 bytes  
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x25d bytes  
PresentationFramework.dll!System.Windows.Controls.Control.MeasureOverride(System.Windows.Size constraint) + 0x5e bytes  
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x533 bytes  
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x25d bytes  
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureChild(ref System.Windows.Controls.Primitives.IItemContainerGenerator generator, ref System.Windows.Controls.Primitives.IContainItemStorage itemStorageProvider, ref System.Windows.Controls.Primitives.IContainItemStorage parentItemStorageProvider, ref object parentItem, ref bool hasUniformOrAverageContainerSizeBeenSet, ref double computedUniformOrAverageContainerSize, ref double computedUniformOrAverageContainerPixelSize, ref bool computedAreContainersUniformlySized, ref System.Collections.IList items, ref object item, ref System.Collections.IList children, ref int childIndex, ref bool visualOrderChanged, ref bool isHorizontal, ref System.Windows.Size childConstraint, ref System.Windows.Rect viewport, ref System.Windows.Controls.VirtualizationCacheLength cacheSize, ref System.Windows.Controls.VirtualizationCacheLengthUnit cacheUnit, ref bool foundFirstItemInViewport, ref double firstItemInViewportOffset, ref System.Windows.Size stackPixelSize, ref System.Windows.Size stackPixelSizeInViewport, ref System.Windows.Size stackPixelSizeInCacheBeforeViewport, ref System.Windows.Size stackPixelSizeInCacheAfterViewport, ref System.Windows.Size stackLogicalSize, ref System.Windows.Size stackLogicalSizeInViewport, ref System.Windows.Size stackLogicalSizeInCacheBeforeViewport, ref System.Windows.Size stackLogicalSizeInCacheAfterViewport, ref bool mustDisableVirtualization, bool isBeforeFirstItem, bool isAfterFirstItem, bool isAfterLastItem, bool skipActualMeasure, bool skipGeneration, ref bool hasBringIntoViewContainerBeenMeasured, ref bool hasVirtualizingChildren) + 0x408 bytes 
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(System.Windows.Size constraint, ref double? lastPageSafeOffset, ref System.Collections.Generic.List<double> previouslyMeasuredOffsets, ref double? lastPagePixelSize, bool remeasure) + 0x184d bytes   
PresentationFramework.dll!System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(System.Windows.Size constraint) + 0xda bytes   
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) + 0x533 bytes  
PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) + 0x25d bytes  
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() + 0x208 bytes   
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayoutCallback(object arg) + 0x22 bytes  
PresentationCore.dll!System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() + 0x91 bytes   
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget) + 0x95 bytes   
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget) + 0x71 bytes   
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x69 bytes 
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) + 0x35 bytes    
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() + 0x101 bytes 
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj) + 0x47 bytes  
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x160 bytes 
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) + 0x14 bytes  
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x52 bytes    
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0xc8 bytes 
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0x60 bytes  
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() + 0x1f4 bytes    
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x6d bytes 
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0xbf bytes    
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x80 bytes    
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x69 bytes 
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) + 0x35 bytes    
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) + 0x164 bytes 
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) + 0x14b bytes

所以我的问题是:如何避免卡住并仍然具有分组虚拟化?

最佳答案

如果我指定

VirtualizingPanel.ScrollUnit="Item"

滚动时它不会卡住。

这很奇怪,因为:

Property Value Type: System.Windows.Controls.ScrollUnit

A value that indicates whether scrolling is measured as items in the collection or as pixels. The default is Item.



对我来说,这一切似乎都是 WPF 中的另一个错误。

关于wpf - 在对虚拟化 ListView 进行分组时,如何避免 VirtualizingStackPanel.MeasureOverride 卡住?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49406195/

相关文章:

c# - 对未知列使用特定的 DataTemplate

WPF数据绑定(bind)计时问题

c# - 用路径数据wpf绘制箭头

WPF 性能 : Displaying thousands of Paths/Shapes on a Canvas

c# - 在组合框中以其自己的样式显示字体样式

c# - 如何实现类似VS 2010的 float 选项卡?

c# - ISupportIncrementalLoading 只触发一次

wpf - DataGrid 滚动问题修复导致性能和内存问题

c# - WPF DataGrid 的 EnableRowVirtualization 和 VirtualizingStackPanel.IsVirtualizing 属性之间的区别

wpf - 使用 VirtualizationMode.Recycling 时,TreeView 错误地将项目显示为展开状态