user380719
user380719

Reputation: 9903

How can I get the element at the mouse position even when the mouse is captured?

Is there a way to get the element at the mouse position?

I am using Mouse.DirectlyOver.

It works fine only if the mouse is not captured. If the mouse is captured, it gets the element with mouse capture which is not necessarily the element at mouse position. In fact, the MSDN documentation says :

If an element has mouse capture, the mouse pointer is considered directly over the element regardless of the where the mouse pointer is.

Is there a workaround?

Upvotes: 2

Views: 8715

Answers (2)

manji
manji

Reputation: 47978

You could try using VisualTreeHelper.HitTest

Upvotes: 0

Robert Levy
Robert Levy

Reputation: 29083

Perform a hittest http://msdn.microsoft.com/en-us/library/ms608753.aspx. Use your window as the 'reference' parameter and pass in a PointHitTestParameters object. For that object, set the point with Mouse.GetPosition( yourWindow )

Upvotes: 2

Related Questions