I have a button. On Button.MouseRightButtonDown, I'm calling Mouse.Capture(button), because I want to detect if someone releases right-click outside of the Button.
I also have a Button.MouseLeave event registered. If someone right-click-drags the mouse off the button, I want this event to trigger.
Unfortunately, it seems like Mouse.Capture somehow blocks MouseLeave from occuring.
Does anyone know a workaround, or maybe can point out where I'm going wrong?
(By the way, if anyone's curious what I'm doing this for, see my other question.)
Following on from my answer to your related question, if you use
CaptureMouse()
fromUIElement
in place of Mouse.Capture(...) then you will see the correct behaviour.When mouse is captured, you can use MouseMove and hit-testing to determine whether the mouse within your element or another.
The following code can be used to avoid tree walk: