See the section "Hit Testing and Z-Order" here: Hit Testing in the Visual Layer, and a code example here: VisualTreeHelper.HitTest Method.
In short, you need to use one of the HitTest()
methods that take a HitTestResultCallback
, and then from your callback return HitTestResultBehavior.Continue
until you reach the element you're looking for:
Point pt = ...
VisualTreeHelper.HitTest(myCanvas, null,
new HitTestResultCallback(MyHitTestResult),
new PointHitTestParameters(pt));
...
private HitTestResultBehavior MyHitTestResult(HitTestResult result)
{
DoSomethingWith(result.VisualHit);
//Set the behavior to return visuals at all z-order levels.
return HitTestResultBehavior.Continue;
}