How to control the order of elements that receive mouse events?

I have a ListView with a bunch of elements in it (the “Considerations” column with the blue elements), and those elements have a little square to their right that you can click & drag

I need to make sure that when I click on that square specifically, the list element doesn’t get selected, but I can’t figure out how to do this. My draggable square is a simple VisualElement with a custom MouseManipulator for drag n drop functionality. That manipulator registers to MouseDownEvent callbacks, and calls “e.StopPropagationImmediate();”, but the MouseDownEvent of my draggable square gets detected after the list element click, so the list element still gets selected

Hi PhilSA,

Without going into specifics of what your code is doing, a first thing you should consider is to “upgrade” your MouseDownEvent to a PointerDownEvent instead. The former is considered a legacy event kept mostly for compatibility, while the latter is the more general event and is usually better by default (for example it handles touch input).

The reason you’re having problems intercepting the ListView’s selection is because the ListView is listening for PointerDown/PointerUpEvents, which are sent before the corresponding MouseDown/MouseUpEvents and are always handled in priority.

1 Like