I am using the Silverlight Toolkit ListBoxDragDropTarget and running into errors using it with dynamically added lists. I am dynamically adding user controls containing lists to a layout Grid. When I drag an item from one list to another in the Grid, I get the following Exception.
throw new Error("Unhandled Error in Silverlight 2 Application Value does not fall within the expected range.
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)\n a开发者_运维问答t 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 that, Int32 index, Object item)\n ....
I can't pin point the exact answer, but Unhandled Error in Silverlight 2 Application Value does not fall within the expected range is going to be a reference (probably binding) to an item that does not exist.
If the lists are dynamic perhaps the Visual Tree does not have a reference to the item you are dragging? You might get over this using an MVVM pattern, and binidng your lists to ObservableCollection properties in your VM.
Can you post a more complete code repro?
精彩评论