【发布时间】:2012-07-15 17:26:20
【问题描述】:
我们经常遇到 DataGrid 的此异常,我们正在尝试重现它,但我们无法找到此问题的原因。
StackTrace 是这样的:
System.Windows.Controls.ItemCollection.GetItemAt(Int32 index) en System.Windows.Controls.VirtualizedCellInfoCollection.Contains(DataGridCell cell) en System.Windows.Controls.DataGridCell.PrepareCell(Object item, DataGridRow ownerRow, Int32 index) en System.Windows.Controls.DataGridCell.PrepareCell(Object item, ItemsControl cellsPresenter, DataGridRow ownerRow) en System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item) en System.Windows。 Controls.ItemContainerGenerator.OnItemReplaced(Object oldItem, Object newItem, Int32 index) zh System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) zh System.Windows.Controls.ItemContainerGenerator.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e) en System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list) en System.W indows.WeakEventManager.DeliverEvent(Object sender, EventArgs args) en System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e) en System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) en System.Windows.Controls。 ItemCollection.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e) en System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list) en System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args) en System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) en System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs args, Int32adjustedOldIndex, Int32adjustedNewIndex) en System.Windows.Controls.MultipleCopiesCollection.set_CopiedItem(对象值) zh System.Windows.Controls.DataGridR ow.NotifyPropertyChanged(DependencyObject d, String propertyName, DependencyPropertyChangedEventArgs e, DataGridNotificationTarget 目标) en System.Windows.Controls.DataGridRow.NotifyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e, DataGridNotificationTarget 目标) en System.Windows.Controls.DataGridRow.OnNotifyRowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) en System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) en System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) en System.Windows.Controls.DataGridRow.OnPropertyChanged(DependencyPropertyChangedEventArgs e) en System.Windows.DependencyObject.NotifyPropertyChange( DependencyPropertyChangedEventArgs args) en System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata 元数据, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithD eferredReference, Boolean coerceWithCurrentValue, OperationType operationType) en System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, 对象值, PropertyMetadata 元数据, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) en System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) en System.Windows.Controls.DataGridRow.PrepareRow(Object item, DataGrid owningDataGrid) en System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject element, Object item) en System.Windows.Controls.ItemsControl.MS.Internal。 Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item) zh System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex, UIElement container, Boolean isRecycled) zh System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newRealized) en System.Window s.Controls.VirtualizingStackPanel.GeneratePreviousChild(Int32 childIndex, Size layoutSlotSize) en System.Windows.Controls.VirtualizingStackPanel.EnsureTopCapGenerated(Size layoutSlotSize) en System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint) en System.Windows.Controls.Primitives .DataGridRowsPresenter.MeasureOverride(Size constraint) zh System.Windows.FrameworkElement.MeasureCore(Size availableSize) zh System.Windows.UIElement.Measure(Size availableSize) zh System.Windows.ContextLayoutManager.UpdateLayout() zh System.Windows.ContextLayoutManager.UpdateLayoutCallback (对象 arg) System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) System.Windows.Threading .ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 和 MS.Internal.Threading。 ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
或者这个:
在 System.Windows.Controls.ItemCollection.GetItemAt(Int32 index) at System.Windows.Controls.VirtualizedCellInfoCollection.Contains(DataGridCell cell) at System.Windows.Controls.DataGridCell.PrepareCell(Object item, DataGridRow ownerRow, Int32 index )在 System.Windows.Controls.DataGridCell.PrepareCell(对象项,ItemsControl cellsPresenter,DataGridRow ownerRow)在 System.Windows.Controls.Primitives.DataGridCellsPresenter.SyncProperties(布尔 forcePrepareCells)在 System.Windows.Controls.DataGridRow.SyncProperties(布尔 forcePrepareCells ) 在 System.Windows.Controls.ItemsControl.MS.Internal.Controls 的 System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject 元素,对象项) 的 System.Windows.Controls.DataGridRow.PrepareRow(Object item, DataGrid owningDataGrid)。 IGeneratorHost.PrepareItemContainer(DependencyObject 容器,对象项)在 System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex,UIElement 容器,布尔 i sRecycled) 在 System.Windows.Controls.VirtualizingStackPanel.GeneratePreviousChild(Int32 childIndex, Size layoutSlotSize) 在 System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex, UIElement child, Boolean newRealized) 在 System.Windows.Controls.VirtualizingStackPanel.EnsureTopCapGenerated(在 System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(大小约束)在 System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(大小约束)在 System.Windows.FrameworkElement.MeasureCore(大小可用大小)在 System.Windows 的大小 layoutSlotSize)。 UIElement.Measure(Size availableSize) 在 System.Windows.ContextLayoutManager.UpdateLayout() 在 System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() 在 System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg) 在 System.Windows.Media.MediaContext。 System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) 处的 RenderMessageHandlerCore(Object resizedCompositionTarget) resizedCompositionTarget) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 在 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
我们发现了一些关于 EnableColumnVirtualization(设置为 false)的帖子,但这无济于事,我们仍然遇到同样的异常。对于如何重现或修复此异常,我们几乎没有想法。有没有人知道如何解决这个问题?
【问题讨论】:
-
只有一个加载了项目的 DataGrid,根本无法通过索引访问任何内容。
标签: c# wpf exception crash wpfdatagrid