#664 – MouseEnter and MouseLeave Events
October 9, 2012 1 Comment
An UIElement will fire a MouseEnter event when its IsMouseOver property becomes true. It will fire a MouseLeave event when its IsMouseOver property becomes false.
These are both direct events, i.e. they don’t bubble or tunnel, but fire only for the UIElement whose IsMouseOver property is changing.
Suppose that we have a Button contained in a StackPanel that is in a Window.
If we move the mouse into the area of the Window that is not covered by the StackPanel, the MouseEnter for the Window will fire.
If we then move into the StackPanel, we’ll get a MouseEnter for the StackPanel, but we will not get a MouseLeave event for the Window–because the pointer is still located in the Window.
Moving over the Button fires its MouseEnter event.
Moving out of the Button along its top edge triggers MouseLeave events for the Button, the StackPanel, and the Window.
Pingback: Dew Drop – October 9, 2012 (#1,418) | Alvin Ashcraft's Morning Dew