Hit Testing in WPF

user242408 picture user242408 · Jan 4, 2010 · Viewed 8.6k times · Source

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 !

Answer

Reed Copsey picture Reed Copsey · Jan 4, 2010

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.