0

我正在使用 Silverlight 工具包ListBoxDragDropTarget并在使用动态添加列表时遇到错误。我正在将包含列表的用户控件动态添加到布局网格中。当我在网格中将一个项目从一个列表拖到另一个列表时,我得到以下异常。


在 MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)\n
在 MS.Internal.XcpImports.MethodPack 处抛出新错误(“Silverlight 2 应用程序值中的未处理错误不在预期范围内。(IntPtr objectPtr, String methodName, Object[] rawData)\n 在 MS.Internal.XcpImports.Collection_Insert[T](PresentationFrameworkCollection 1 collection, Int32 index, Object value)\n at System.Windows.PresentationFrameworkCollection1.InsertImpl(Int32 index, Object value)\n 在 System.Windows.Controls.ItemCollection.InsertImpl( Int32 索引,对象值)\n 在 System.Windows.Controls.ItemCollection.InsertInternal(Int32 索引,对象值)\n 在 System.Windows.PresentationFrameworkCollection`1.Insert(Int32 索引,T 值)\n 在 System.Windows .Controls.ItemsControlExtensions.InsertItem(ItemsControl that, Int32 index, Object item)\n
……

4

1 回答 1

0

我无法确定确切的答案,但Silverlight 2 应用程序值中未处理的错误不在预期范围内,这将是对不存在的项目的引用(可能绑定)。

如果列表是动态的,也许可视树没有对您正在拖动的项目的引用?您可以使用 MVVM 模式克服这个问题,并将您的列表绑定到 VM 中的 ObservableCollection 属性。

您可以发布更完整的代码复制吗?

于 2009-12-14T12:28:07.640 回答