Hit Testing in WPF

2019-06-17 06:51发布

问题:

I have an Ellipse on a Canvas and I'm doing Hit Testing on it. Every time I click the stroke of the Ellipse, the test passes. If I click in the middle of the Ellipse, the test fails. This is good!

After I fill the ellipse like this: myEllipse.Fill = new SolidColorBrush(Colors.Blue);, the test pasess also when I click in the middle of the Ellipse.

How can I disable this? (even when Ellipse is Filled, the test will fail when I click in the middle) Thanks !

回答1:

If you do your own hit testing (see Hit Testing in the Visual Layer for details on how to do this), you should be able to check the IntersectionDetail of the GeometryHitTestResult is IntersectionDetail.Intersects, and not IntersectionDetail.FullyContains.



回答2:

Cant you put a smaller ellipse in the middle of it and set IsHitTestVisible="false" ?