Arrgh! MouseEnter & MouseLeave with grid

Have been messing around with my wpf application today, specifically trying to animate a button's opacity when the mouse is over the whole user control that the button is in.

This is a relatively straightforward bit of xaml to build, however it worked almost as expected. The mouse leave event seemed to be triggered when the mouse was still over the user control's main grid, but only when it wasn't over any actual content. As long as it was over textblocks etc, it was fine. After some googling I discovered that the mouse 'drops through' if the element doesn't have a background. Set the main grid background property to transparent and "Hey Presto!" no more mouse leave events in the middle of my control.

Comments are closed