重现异常:指定的参数超出有效值范围。参数名称:索引 - c#

我们经常为DataGrid遇到此异常,并且试图重现它,但是我们找不到导致此问题的原因。

StackTrace可能是这样的:

System.Windows.Controls.ItemCollection.GetItemAt(Int32索引)zh-CN System.Windows.Controls.VirtualizedCellInfoCollection.Contains(DataGridCell单元格)zh-CN System.Windows.Controls.DataGridCell.PrepareCell(对象项,DataGridRow ownerRow,Int32索引) Windows.Controls.DataGridCell.PrepareCell(Object item,ItemsControl cellsPresenter,DataGridRow ownerRow)zh-CN System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject容器,Object项)zh_cn System.Windows.Controls.ItemContainerGenerator .OnItemReplaced(Object oldItem,Object newItem,Int32索引)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)System.Windows.WeakEventManager.DeliverEventToList(对象发送者,EventArgs args,ListenerList列表)zh_cn System.Wind ows.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,对象发送者,EventArgs e)zh-CN System.Windows.WeakEventManager.DeliverEventToList(对象发送者,EventArgs args,ListenerList列表)zh-CN System.Windows.WeakEventManager.DeliverEvent(对象发送者,EventArgs args)System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs args Int32 AdjustedOldIndex Int32 AdjustedNewIndex)System.Windows.Controls.MultipleCopiesCollection(Object_Copied) zh_cn System.Windows.Controls.DataGridRow。 NotifyPropertyChanged(DependencyObject d,字符串propertyName,DependencyPropertyChangedEventArgs e,DataGridNotificationTarget目标)zh-CN System.Windows.Controls.DataGridRow.NotifyPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e,DataGridNotificationTarget目标) )System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)System.Windows.Controls.DataGridRow.OnPropertyChanged(DependencyPropertytyChangedEventArgs e) )System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata元数据,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,布尔值coerceWithDefe rredReference,布尔值coerceWithCurrentValue,OperationType operationType)zh-cn System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp,对象值,PropertyMetadata元数据,布尔值coerceWithDeferredReference,布尔值coerceWithCurrentValue,OperationType操作类型,布尔值isInternal)在System.Windows.DependencyObject。对象值)zh_cn System.Windows.Controls.DataGridRow.PrepareRow(对象项,DataGrid owneringDataGrid)zh-CN System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject元素,对象项)zh-CN System.Windows.Controls.ItemsControl.MS.Internal。 Controls.IGeneratorHost.PrepareItemContainer(DependencyObject容器,对象项)zh-CN System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex,UIElement容器,Boolean isRecycled)zh-CN System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex,UIElement子级,Boolean新实现的)System.Windows.C ontrols.VirtualizingStackPanel.GeneratePreviousChild(Int32 childIndex,Size layoutSlotSize)zh-CN System.Windows.Controls.VirtualizingStackPanel.EnsureTopCapGenerated(Size布局SlotSize)zh-CN System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size约束)zh-CN System.Windows.Controls.Primitives.DataGridRowsPresenter .MeasureOverride(大小约束)zh-CN System.Windows.FrameworkElement.MeasureCore(大小availableSize)zh-CN System.Windows.UIElement.Measure(大小availableSize)zh-CN System.Windows.ContextLayoutManager.UpdateLayout()zh-CN 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(Delegate回调,Object args,Int32 numArgs)zh-CN MS.Internal.Threading.Exc eptionFilterHelper.TryCatchWhen(对象源,委托方法,对象args,Int32 numArgs,委托catchHandler)

或者这个:

在System.Windows.Controls.VirtualizedCellInfoCollection.Contains(DataGridCell单元)在System.Windows.Controls.DataGridCell.PrepareCell(对象项,DataGridRow ownerRow,Int32索引)在System.Windows.Controls.ItemCollection.GetItemAt(Int32索引) System.Windows.Controls.Primitives.DataGridCellsPresenter.SyncProperties(Boolean forcePrepareCells)(System.Windows.Controls.DataGridRow.SyncProperties(Boolean forcePrepareCells))上的.Windows.Controls.DataGridCell.PrepareCell(Object item,ItemsControl cellsPresenter,DataGridRow ownerRow) System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(DependencyObject element,Object item)处的System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer处的.Windows.Controls.DataGridRow.PrepareRow(对象项,DataGrid owningDataGrid) (DependencyObject容器,Object项)位于System.Windows.Controls.VirtualizingStackPanel.InsertContainer(Int32 childIndex,UIElement容器,布尔值isRe在System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex,UIElement child,Boolean新实现)处System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(Int32 childIndex,Size layoutSlotSize)在System.Windows.Controls.VirtualizingStackPanel.EnsureTopCapGenerated( System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(大小约束)(位于System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(大小约束)位于System.Windows.FrameworkElement.MeasureCore(大小可用)在System.Windows。在System.Windows.Media.MediaContext处,System.Windows.Context.Manager.UpdateLayout()在System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()处,在System.Windows.ContextLayoutManager.UpdateLayout()处,UIElement.Measure(Size availableSize)。 System.Windows.Media.MediaContext.RenderMessageHandler(Object re)上的RenderMessageHandlerCore(Object resizedCompositionTarget) (System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate回调,Object args,Int32 numArgs)at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,Delegate method,Object args,Int32 numArgs,Delegate catchHandler)

我们发现了一些有关EnableColumnVirtualization的帖子(设置为false),但这无济于事,我们仍然遇到相同的异常。关于如何重现或修复此异常,我们几乎没有想法。是否有人对如何解决此问题有想法?

参考方案

可能的解决方法:

http://www.actiprosoftware.com/community/thread/5522/argumentoutofrangeexception-when-using-wpf-da

查看解决方法标签:

http://connect.microsoft.com/VisualStudio/feedback/details/643908/argumentoutofrangeexception-buried-deep-in-datagrid-code#

修补程序:

http://support.microsoft.com/kb/2484832

“没有找到适合完成此操作的成像组件。” - c#

我已经编写了一个应用程序,需要下载* .png文件并将其设置为WPF中按钮的背景。因此,当我运行此程序时,它会遇到以下错误: 找不到适合完成此操作的成像组件。”我的代码如下:第一个应用程序使用WebClient类的对象下载文件:System.Net.WebClient wClient = new System.Net.WebClient(); Uri dow…

在硬件级别模拟按键-Windows - java

我正在寻找一种语言或库,以使我可以尽可能地模拟按键,而无需实际按下按键。(我对按键级别的具体衡量标准是,当我的计算机已经在运行按键侦听器(例如MouseKey和StickyKeys)时,它是否会产生与物理按键相同的输出。)我已经尝试了许多模拟按键的方法。Java AWT库,Java win32api,python win32com sendKeys,pyth…

Windows Service增加CPU消耗 - c#

在我的工作中,我负责使用C#2003编写的六个Windows服务。每个服务都包含一个计时器,该计时器每分钟左右触发一次,大部分工作都在该计时器上进行。我的问题是,随着这些服务的运行,即使没有任何有意义的工作要做,它们也会在循环的每次迭代中消耗越来越多的CPU时间(即,它们只是闲着,浏览数据库)做某事)。当它们启动时,每个服务平均使用4个CPU的(大约)2-3…

Windows Media Player如何处理监视器的刷新率? - c#

我正在C#/ WinForms中编写动画应用程序(请参见this question)。基本上,我应用程序中的动画是平滑的,但显示出撕裂效果;当我拍摄相同的动画并将其渲染为AVI文件并使用Windows Media Player播放时,该动画完全没有显示撕裂效果。我知道WMP不会更改帧速率,因为动画与音乐同步。我假设WMP使用DirectX或其他知道监视器刷新…

Windows 8 Metro应用程序的图表 - c#

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely …