views:

2946

answers:

3

Is there a way with WPF to get an array of elements under the mouse on a MouseMove event?

+2  A: 

You can also try using the Mouse.DirectlyOver property to get the top-most element that is under the mouse.

Andy
+5  A: 

From "WPF Unleashed", page 383:

Visual hit testing can inform you about all Visuals that intersect a location, [...] you must use [...] the [VisualTreeHelper.]HitTest method that accepts a HitTestResultCallback delegate. Before this version of HitTest returns, the delegate is invoked once for each relevant Visual, starting from the topmost and ending at the bottommost.

The signature of such a callback is

HitTestResultBehaviour Callback(HitTestResult result)

and it has to return HitTestResultBehaviour.Continue to receive further hits.

For further information, please consult the MSDN documentation for VisualTree.HitTest.


P.S.: Yes, I can recommend the book ;-)

David Schmitt