Hit Testing in WPF

2019-06-17 06:38发布

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 !

2条回答
做个烂人
2楼-- · 2019-06-17 07:21

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

查看更多
我想做一个坏孩纸
3楼-- · 2019-06-17 07:26

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.

查看更多
登录 后发表回答