Search code examples
.netwpflistbox

WPF Disable the item selection on MouseMove of a ListBox


If I press the mouse on an item of a ListBox and then move the mouse without releasing the mouse-button over another item, the selection automatically changes to the element that is under the mouse.

Is there a possibility to disable this behaviour, so that the selection is only changed when the mouse has been pressed directly over the item (I need this for initiation Drag&Drop with multiple selected items, the default-behaviour has an ugly side-effect)?

Or alternatively, is there a good example for drag&drop that resolves all the obstacles that arise when implementing drag&drop for multiple items with a ListBox.


Solution

  • This is the default behavior of the listbox, and cannot be changed.

    There are 2 tricks you should try: 1. Subscribe to preview mouse up and mark the handled to true. 2. Inherit items control and implement your own selector.