重现异常:指定的参数超出了有效值的范围。参数名称:index

时间:2012-07-16 19:49:54

标签: c# wpf exception crash wpfdatagrid

我们经常为DataGrid获取此异常,并且我们正在尝试重现它,但我们无法找到此问题的原因。

StackTrace就是这样:


System.Windows.Controls.ItemCollection.GetItemAt(Int32 index)zh_cn System.Windows.Controls.VirtualizedCellInfoCollection.Contains(DataGridCell cell)zh_cn System.Windows.Controls.DataGridCell.PrepareCell(Object item,DataGridRow ownerRow,Int32 index) zh_cn System.Windows.Controls.DataGridCell.PrepareCell(Object item,ItemsControl cellsPresenter,DataGridRow ownerRow)zh_cn System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container,Object item)zh_cn System.Windows。 Controls.ItemContainerGenerator.OnItemReplaced(Object oldItem,Object newItem,Int32 index)zh_cn System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender,NotifyCollectionChangedEventArgs args)zh_cn System.Windows.Controls.ItemContainerGenerator.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType,Object sender,EventArgs e)zh_cn System.Windows.WeakEventManager.DeliverEventToList(Object sender,EventArgs args,ListenerList list)zh System.W indows.WeakEventManager.DeliverEvent(Object sender,EventArgs args)zh_cn System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender,NotifyCollectionChangedEventArgs e)zh_cn System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)zh_cn System.Windows.Controls。 ItemCollection.System.Windows.IWeakEventListener.ReceiveWeakEvent(类型managerType,Object sender,EventArgs e)zh_cn System.Windows.WeakEventManager.DeliverEventToList(Object sender,EventArgs args,ListenerList list)zh_cn System.Windows.WeakEventManager.DeliverEvent(Object sender,EventArgs args)zh_cn System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)zh_cn System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs args,Int32 adjustedOldIndex,Int32 adjustedNewIndex)zh_cn System.Windows.Controls.MultipleCopiesCollection.set_CopiedItem(Object value) en System.Windows.Controls.DataGridR ow.NotifyPropertyChanged(DependencyObject d,String propertyName,DependencyPropertyChangedEventArgs e,DataGridNotificationTarget target)zh_cn System.Windows.Controls.DataGridRow.NotifyPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e,DataGridNotificationTarget target)zh_cn 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)zh_cn System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata metadata,EffectiveValueEntry oldEntry,EffectiveValueEntry& newEntry,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationType operationType)zh_cn System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp,Object value,PropertyMetadata metadata,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationType operationType,Boolean isInternal)zh_cn System.Windows.DependencyObject.SetValue( DependencyProperty dp,Object value)zh_cn System.Windows.Controls.DataGridRow.PrepareRow(Object item,DataGrid owningDataGrid)zh_cn System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject element,Object item)zh_cn System.Windows.Controls.ItemsControl.MS .Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject容器,Object项)zh_cn System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex,UIElement container,Boolean isRecycled)zh_cn System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex,UIElement孩子,布尔ne wlyRealized)zh_cn System.Windows.Controls.VirtualizingStackPanel.GeneratePreviousChild(Int32 childIndex,Size layoutSlotSize)zh_cn System.Windows.Controls.VirtualizingStackPanel.EnsureTopCapGenerated(Size layoutSlotSize)zh_cn System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)zh System。 Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint)zh System.Windows.FrameworkElement.MeasureCore(Size availableSize)zh_cn System.Windows.UIElement.Measure(Size availableSize)zh_cn System.Windows.ContextLayoutManager.UpdateLayout()en System。 Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)zh_cn System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()zh_cn System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)zh_cn System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)zh_cn System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象args,Int32 numAr gs)en MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,Delegate方法,Object args,Int32 numArgs,Delegate catchHandler)


或者这个:


在System.Windows.Controls.VirtualizedCellInfoCollection.Contains(DataGridCell单元格)System.Windows.Controls.DataStrid.PetpareCell(对象项,DataGridRow ownerRow,Int32索引)的System.Windows.Controls.ItemCollection.GetItemAt(Int32索引) )在System.Windows.Controls.DataStrid上的System.Windows.Controls.DataGridCell.PrepareCell(Object item,ItemsControl cellsPresenter,DataGridRow ownerRow)处于System.Windows.Controls.DataGridRow.SyncProperties(Boolean forcePrepareCells)的System.Windows.Controls.Primitives.DataGridCellsPresenter.SyncProperties(Boolean forcePrepareCells) )System.Windows.Controls.ItemsControl.MS.Internal.Controls中System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject元素,Object item)的System.Windows.Controls.DataGridRow.PrepareRow(Object item,DataGrid owningDataGrid)。 System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex,UIElement container,Boolean i)中的IGeneratorHost.PrepareItemContainer(DependencyObject容器,Object项) sRecycled)在System.Windows.Controls.VirtualizingStackPanel.EnsureTopCapGenerated的System.Windows.Controls.VirtualizingStackPanel.GeneratePreviousChild(Int32 childIndex,Size layoutSlotSize)上的System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex,UIElement child,BooleannewRealized)。在System.Windows上的System.Windows.FrameworkElement.MeasureCore(Size availableSize)的System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size约束)处的System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size约束)处调整sizeSlotSize大小。 System.Windows.Media.MediaContext上的System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()处的System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)处的System.Windows.ContextLayoutManager.UpdateLayout()处的UIElement.Measure(Size availableSize)。 System.Windows.Media.MediaContext.RenderMessageHandler(Object中的RenderMessageHandlerCore(Object resizedCompositionTarget) ResizedCompositionTarget)在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源,委托方法,对象args,Int32 numArgs,Delegate catchHandler)的System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象args,Int32 numArgs)中


我们发现了一些关于EnableColumnVirtualization的帖子(设置为false),但这没有帮助,我们仍然得到相同的异常。我们几乎没有关于如何重现或修复此异常的想法。有没有人知道如何解决这个问题?