When I am using System.Windows.Media.VisualTreeHelper.HitTest
on mouse clicking canvas, it always returns me the element on top. I mean if there are two elements overlapping each other, the one I get is the one with higher ZIndex in canvas.
I also tried to do it this way, but even after I made IsHitTestVisible = False
it still returned this same one to me.
Is there any possibility to get the element "underneath"?
Thanks in advance!
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 aHitTestResultCallback
, and then from your callback returnHitTestResultBehavior.Continue
until you reach the element you're looking for: