#667 – IsMouseOver vs. IsMouseDirectlyOver

The IsMouseOver property for a user interface element indicates whether the mouse is currently located over the element or any of its children.  For example, for a Button contained in a StackPanel, when the user moves the mouse over the ButtonIsMouseOver will be true for both the Button and the StackPanel.

The IsMouseDirectlyOver, on the other hand, indicates whether the mouse is over a control and not over any of its children.

In the example below, when the mouse is over the button, the StackPanel’s IsMouseOver property is true, but its IsMouseDirectlyOver property is false.

 

Notice that IsMouseDirectlyOver is also false for the Button.  This is because the mouse is actually pointing to some child element within the Button element.

If we move the mouse back off the Button, but still within the StackPanel, its IsMouseDirectlyOver property becomes true.

Advertisements