WPF events and event drag and drop?

I have a ListBox WPF in which elements have a Button style. I used gong-wpf-dragdrop to make drag-and-drop very easy, so I can reorder the lists. However, now I would like to be able to left-click on one of the buttons to start the editing action, but the MouseLeftButtonUp event in the ListBox is apparently absorbed by the drag and drop operation. (I use EventToCommand from MVVM Light to connect everything).

Changing the ListBox to respond to MouseRightButtonUp works fine (so I can drag and drop with the left mouse button and trigger the edit action with the right mouse button), but I would prefer to save the right mouse button for the context menu.

I also tried using MouseDoubleClick, but although this triggered the editing action, it always opened the first item in the list for editing and moved the list that was double-clicked to the top of the list - very confusing for all interested parties.

Any thoughts on how to approach this?

+4
source share
1 answer

If you understand correctly, you do not want to drag and drop if you click the button. One way to do this is to connect to the PreviewMouseLeftButtonDown button. Initiate the editing of the action in the event handler and set e.Handled = true. Thus, MouseLeftButtonDown will not appear in the list, and the drag operation will not be initiated. One of the drawbacks is that the button will respond to mousedown instead of mouseup (like ClickMode = Click).

Regards Rob

+1
source

All Articles