开发者

Silverlight 3 Toolkit - ListBoxDragDropTarget

I have two listboxes that I am dragging one item from to the other. Using the November 2009 build of the Silverlight 3 Toolkit's ListBoxDragDropTarget. I have an EventHandler on the Drop event of the second listbox. I am trying to get the index of the item that is being inserted so I can see what comes before it in the item collection. Does anyone know how to get the index of the item to be a开发者_如何学编程dded on a dropped item?


I think I figured out the solution.

On the ListBox (toList) there is a ItemsContainerGenerator which has an event ItemsChanged. I was able to get the item being dropped into the ListBox by checking to make sure the ItemsChangedEventArgs (e) action was add and then figuring out the index based on the position that was returned from the ItemsChangedEventArgs. Below is the code.

Just passed the InitializeComponent() add the new event handler.

toList.ItemContainerGenerator.ItemsChanged += new System.Windows.Controls.Primitives.ItemsChangedEventHandler(ItemContainerGenerator_ItemsChanged);

Then add the handler itself.

void ItemContainerGenerator_ItemsChanged(object sender, System.Windows.Controls.Primitives.ItemsChangedEventArgs e){if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { int index = (e.Position.Index + e.Position.Offset);object obj = toList.Items[index];}}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜