R – Silverlight 2.0 RC Drag and drop ordering of a ListBox


I am trying to give a ListBox drag and drop ordering functionality and I have hit a wall. I got it to work when I specify the list box items in xaml but it does not work when I bind to a list it no longer works because the items are no longer of a listboxitem type.

I found this code http://blog.dobaginski.com/josh/?p=52 that allows me to get the underlying ListBoxItem but I can't get the mouse move event to fire.

I have went through other tutorials but have not been able to find one that deals with a ListBox. Has anyone done this with a ListBox.

The events I am using are SelectedChange, MouseMove, and LeftMouseButtonUp (I think that name is right). I am not using LeftMouseButtonDown because I couldn't get it to fire.

Best Solution

As far as i know you cannot get at the listbox item container when using data binding. YOu could in Beta 1.

You also cannot set a mouse event handler in the style, you must use a data template, just so you know.

You will likely have to use the mouse move event from a parent element, probably the UserControl or main layout control that hosts the listbox.

State changes and animations need to be in the style though so... you still cant get at the listbox item, just the element inside it in the data template.

Oh and if doing drag and drop HitTest is now protected so that will make the Drop harder.