Drag&Drop between two/more WPF listboxes

268 Views Asked by At

I am trying to do the following: I have two list-boxes and I want to be able to drag an item from the first one and drop it into the second one.

This works but I have problems when I want to drag an item from the second and drop it in the first one.

If I set "AllowDrop=true" for the first one and use the same code in the PreviewMouseButtonDown and drop, It happens that I can drop in item onto itself.

When I click an item DoDragDrop is called and then Drop. I tried to avoid this by checking if the drag source and the target are the same but after I've done this I've seen that I need to double-click an item in the list-box if I want to select an item. This is annoying and unwanted because sometimes I don't want to move an item to another list-box.

I wish I can select an item by click (see it highlighted) and If I hold down my left button and move the mouse to be able to drop it into the second list-box. Basically, any list-box in my small app should allow dropping and should also be a drag source.

Is it possible that a list-box be a drag-source and a drop target at the same time and avoid dropping its items into itself, this while the user can still select an item with a single click for other actions?

My source was this project but I've added some custom strings in my first list-box, not all the time zones.

0

There are 0 best solutions below