I like the functionality of IsMouseDirectlyOverChanged, but it only works for the topmost elements. What I really want to do is monitor the IsMouseOver property of a control, regardless of its z-index, and receive notification when IsMouseOver is modified. If I owned this property, I could do INotifyPropertyChanged, but unfortunately it’s owned by UIElement. Still learning the ropes of WPF, so maybe this is easy, but I’m not familiar with how to monitor properties that belong to parent classes. Unlike IsMouseDirectlyOver, IsMouseOver doesn’t have a changed event attached.
I like the functionality of IsMouseDirectlyOverChanged, but it only works for the topmost elements.
Share
You can use styles to react to when IsMouseOver is changed.
And later attach the style to an element:
Edit:
If you want to call code from within a style, the solution is rather complex.
First, you have to create a custom UserControl class and give it an attached property. Whenever the attached property is changed, you can use the property changed callback. Here’s the
*.xaml.csfile, just keep the default.xamlfile:You’ll then have to wrap the elements you want to react to in your custom control and make the style change the attached property of that custom control. Example:
Add all your code into the
OnMouseOverIsChangedfunction, and this should work.