我正在使用Silverlight Toolkit ListBoxDragDropTarget 并使用动态添加的列表运行错误。我正在动态地将包含列表的用户控件添加到布局网格中。当我在Grid中将项目从一个列表拖到另一个列表时,我得到以下异常。
抛出新错误(“未处理的错误” Silverlight 2应用程序值 不在预期的范围内。
在 MS.Internal.XcpImports.MethodEx(IntPtr的 ptr,String name,CValue [] cvData)\ n
在 MS.Internal.XcpImports.MethodPack(IntPtr的 objectPtr,String methodName,Object [] rawData)\ n at MS.Internal.XcpImports.Collection_Insert [T](PresentationFrameworkCollection1 collection, Int32 index, Object value)\n at System.Windows.PresentationFrameworkCollection
1.InsertImpl(的Int32 index,Object value)\ n at System.Windows.Controls.ItemCollection.InsertImpl(的Int32 index,Object value)\ n at System.Windows.Controls.ItemCollection.InsertInternal(的Int32 index,Object value)\ n at System.Windows.PresentationFrameworkCollection`1.Insert(的Int32 index,T value)\ n at System.Windows.Controls.ItemsControlExtensions.InsertItem(ItemsControl的 那个,Int32索引,对象项目)\ n
....
答案 0 :(得分:0)
我无法指出确切的答案,但 Silverlight 2中的未处理错误应用程序值不在预期范围内将成为对某个项目的引用(可能是绑定)不存在。
如果列表是动态的,那么Visual Tree可能没有对您要拖动的项目的引用?您可以使用MVVM模式来解决此问题,并将列表binidng到VM中的ObservableCollection属性。
您可以发布更完整的代码重复吗?