I got VisualTreeHelper.HitTest() to finally work. It turns out that the problem was that the ZIndex of the ellipses was preventing the top-most hit test result to show up properly. Since I constructed the ellipses in descending order, the top-most ZIndex’ed element would be the outermost ring, which makes sense since it was made last and should be on top of all the other ellipses. So if I were testing for the innermost ring, it would keep returning the outermost ring, just because it is big enough to encompass that entire area.

This is easily solved by defining the ZIndex of each ellipse in the XAML file, like this:

Canvas.ZIndex=99

The higher the value, the higher the “layer” the element is in.

This is great because the hit test method I wrote myself was pretty bad and the visual tree helper method is much more accurate. This will improve the application a lot and I feel a little less resentful of the Microsoft Surface API.

Advertisements