I have been trying to implement DnD between ListBox controls in WPF and also reordering items in the list box.
The situation that I have is 3 listboxes, one is the "Toolbox" which contains all of the objects that will ever be dragged, one which they get dragged onto, called the "Workfow", and another one called the "Output" which objects from the "Workflow" get dragged from. When dragging, all objects should be copied rather than moved across. The "Toolbox" and "Workflow" listboxes are bound to lists of "Element" objects, and the "Output" listbox is bound to a list of KeyValuePair<string, string> objects which gets populated when the element is dropped from the "Workflow" listbox. A bit complicated I know.
Dragging from "Toolbox" to "Workflow" works fine, and reordering items in "Workflow" works too, but when I try and drag from "Workflow" to "Output" the DragDropState.DraggedItems property is always empty.
Below is my override of the ListBoxDragDropBehavior
The situation that I have is 3 listboxes, one is the "Toolbox" which contains all of the objects that will ever be dragged, one which they get dragged onto, called the "Workfow", and another one called the "Output" which objects from the "Workflow" get dragged from. When dragging, all objects should be copied rather than moved across. The "Toolbox" and "Workflow" listboxes are bound to lists of "Element" objects, and the "Output" listbox is bound to a list of KeyValuePair<string, string> objects which gets populated when the element is dropped from the "Workflow" listbox. A bit complicated I know.
Dragging from "Toolbox" to "Workflow" works fine, and reordering items in "Workflow" works too, but when I try and drag from "Workflow" to "Output" the DragDropState.DraggedItems property is always empty.
Below is my override of the ListBoxDragDropBehavior
public
class
WfBehavior : ListBoxDragDropBehavior
{
public
override
void
Drop(DragDropState state)
{
foreach
(
object
o
in
state.DraggedItems)
{
if
(Dropped !=
null
)
{
Dropped(o
as
Element, state.InsertIndex);
}
}
base
.Drop(state);
}
protected
override
bool
IsMovingItems(DragDropState state)
{
return
state.IsSameControl;
}
public
static
event
DroppedEventHandler Dropped;
}
public
delegate
void
DroppedEventHandler(Element element,
int
index);