WPF DataGrid EnableColumnVirtualization =“真”。在DataGridCellsPanel.get_HasCorrectRealizedColumns()处引发NullReferenceException [英] WPF DataGrid EnableColumnVirtualization="True" Raises NullReferenceException at DataGridCellsPanel.get_HasCorrectRealizedColumns()

查看:258
本文介绍了WPF DataGrid EnableColumnVirtualization =“真”。在DataGridCellsPanel.get_HasCorrectRealizedColumns()处引发NullReferenceException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 EnableColumnVirtualization = True 的WPF数据网格。将显示用户控件,但在您滚动或调整大小时,将在 DataGridCellsPanel.get_HasCorrectRealizedColumns()处收到 NullReferenceException 。设置 ColumnVirtualization = False 可解决此问题。我试着删除 EnableRowVirtualization = True ...等以为这可能是由于属性的组合,但是我能够非常轻松地重现该问题简单的DataGrid:

I have a WPF DataGrid withEnableColumnVirtualization="True". The user control displays but as soon as you scroll or resize you'll receive a NullReferenceException at DataGridCellsPanel.get_HasCorrectRealizedColumns(). Setting ColumnVirtualization="False" corrects the issue. I've tried removing EnableRowVirtualization="True" ... etc thinking that maybe it was due to a combination of properties but I'm able to reproduce the issue with a very simple DataGrid:

<DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="True" EnableColumnVirtualization="True"

还有其他人遇到吗?我正在运行Win764。谢谢大家!

Has anyone else run into this? I'm running Win7 64. Thanks all!

   at System.Windows.Controls.DataGridCellsPanel.get_HasCorrectRealizedColumns()
   at System.Windows.Controls.Primitives.DataGridCellsPresenter.SyncProperties(Boolean forcePrepareCells)
   at System.Windows.Controls.DataGridRow.SyncProperties(Boolean forcePrepareCells)
   at System.Windows.Controls.DataGridRow.PrepareRow(Object item, DataGrid owningDataGrid)
   at System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject element, Object item)
   at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
   at System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled)
   at System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newlyRealized, Boolean isBeforeViewport)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureChild(IItemContainerGenerator& generator, IContainItemStorage& itemStorageProvider, IContainItemStorage& parentItemStorageProvider, Object& parentItem, Boolean& hasUniformOrAverageContainerSizeBeenSet, Double& computedUniformOrAverageContainerSize, Boolean& computedAreContainersUniformlySized, IList& items, Object& item, IList& children, Int32& childIndex, Boolean& visualOrderChanged, Boolean& isHorizontal, Size& childConstraint, Rect& viewport, VirtualizationCacheLength& cacheSize, VirtualizationCacheLengthUnit& cacheUnit, Boolean& foundFirstItemInViewport, Double& firstItemInViewportOffset, Size& stackPixelSize, Size& stackPixelSizeInViewport, Size& stackPixelSizeInCacheBeforeViewport, Size& stackPixelSizeInCacheAfterViewport, Size& stackLogicalSize, Size& stackLogicalSizeInViewport, Size& stackLogicalSizeInCacheBeforeViewport, Size& stackLogicalSizeInCacheAfterViewport, Boolean& mustDisableVirtualization, Boolean isBeforeFirstItem, Boolean isAfterFirstItem, Boolean isAfterLastItem, Boolean skipActualMeasure, Boolean skipGeneration, Boolean& hasBringIntoViewContainerBeenMeasured, Boolean& hasVirtualizingChildren)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size constraint, Nullable`1& lastPageSafeOffset, List`1& previouslyMeasuredOffsets, Boolean remeasure)
   at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
   at System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.Controls.VirtualizingStackPanel.<>c__DisplayClassa.<InitializeViewport>b__7()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run()
   at ....App.Main() in c:\....\obj\Debug\App.g.cs:line 0


推荐答案

我可以通过将 VirtualizationMode 从回收更改为标准来实现这一目标。

I was able to get to it going by changing the VirtualizationMode from Recycling to Standard.

    <DataGrid ItemsSource="{Binding Items}" 
     AutoGenerateColumns="True"
     EnableColumnVirtualization="True"
     Standard.VirtualizingStackPanel.IsVirtualizing="True"
     VirtualizingStackPanel.VirtualizationMode="Standard">

我仍然想知道为什么回收无效... bug?

I'd still like to know why Recycling doesn't work ... bug?

希望这可以帮助遇到相同问题的任何人。

Hope this helps anyone that runs into the same problem.

这篇关于WPF DataGrid EnableColumnVirtualization =“真”。在DataGridCellsPanel.get_HasCorrectRealizedColumns()处引发NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆