I've got an IsMouseOver trigger on my element. I've also got a drag action happening, whereby another element captures the mouse, and thus the IsMouseOver trigger never happens, yet I explicitly want it to happen on certain elements when I drag over it (mouse captured and all). Is this possible?
I know this was asked years ago, but just in case someone lands here from a search engine (just like me), here is how I solved the problem for myself. Instead of using IsMouseOver
property, use hit-testing in your code to determine if mouse is inside your control:
bool IsMouseOverEx = false;
VisualTreeHelper.HitTest(this, d =>
{
if (d == this)
{
IsMouseOverEx = true;
return HitTestFilterBehavior.Stop;
}
else
return HitTestFilterBehavior.Continue;
},
ht => HitTestResultBehavior.Stop,
new PointHitTestParameters(Mouse.GetPosition(this)));
if (IsMouseOverEx)
{
//Do whatever you need in case of MouseOver
}
N.B. If you haven't read the question, note that this method is a workaround for situations where the mouse is "captured" and therefore IsMouseOver
property is not working correctly. In normal situations, you should always use IsMouseOver
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With