1
votes

WPF Panels support the events from the IInputElement interface (most of Mouse events are declared here)

when doing a MouseEnter or a MouseMove in a panel, it wil only do the event when you hover over a childcpntrol from that panel instead of the whole panelspace

example: a Stackpanel (Orientation = horizontal) with a textblock (label in WPF), a textbox and a button. there is a margin of 5 on the button. The Stackpanel has a MouseEnter and a MouseLeave handler. when these event fire, there will be set a some text on the textblock and in the textbox (example: 'Stackpanel entered' and 'Stackpanel left'). the text of the textblock will be renewed, the textbox text will be added.

If you go to your stackpanel from the left to the right (from textblock to button), you will see that the text in the textbox will be as follow: 'Stackpanel entered Stackpanel left Stackpanel entered'.

The MouseLeave event is fired. this is because the white space between the textbox and the button (the margin of the button if you remember).

My question is: what has to change on the stackpanel in order to have no MouseLeave event firing with the same situation and conditions?

In other words: how can the MouseEnter and the MouseLeave event be linked on the Stackpanel itself and not on his children so that all space of the stackpanel is a 'event zone'?

1

1 Answers

4
votes

Looks like the answer has to do with the backgorund color. the Presentation Core assumes that the white space belongs to the parent (or one of the parents) of the Stackpanel.

good solution: override the default background or set the background. this is "Transparent" (RGB: 0 255 255 255, Hex: #00FFFFFF). Value has to be less transparent (RGB: 1 255 255 255, Hex: #01FFFFFF).