private bool HitTestDrawing(GeometryDrawing drawing, Geometry geomDisplay, IntersectionDetail detail) { Pen pen = drawing.Pen; Brush brush = drawing.Brush; if (pen != null && brush == null) { if (drawing.Geometry.StrokeContainsWithDetail(pen, geomDisplay) == detail) { return(true); } Geometry geometry = drawing.Geometry; LineGeometry line = null; EllipseGeometry ellipse = null; RectangleGeometry rectangle = null; PathGeometry path = null; if (TryCast.Cast(geometry, out path)) { PathFigureCollection pathFigures = path.Figures; int itemCount = pathFigures.Count; if (itemCount == 1) { if (pathFigures[0].IsClosed && path.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } else { for (int f = 0; f < itemCount; f++) { PathFigure pathFigure = pathFigures[f]; if (pathFigure.IsClosed) { PathFigureCollection testFigures = new PathFigureCollection(); testFigures.Add(pathFigure); PathGeometry testPath = new PathGeometry(); testPath.Figures = testFigures; if (testPath.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } } } } else if (TryCast.Cast(geometry, out line)) { if (line.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } else if (TryCast.Cast(geometry, out ellipse)) { if (ellipse.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } else if (TryCast.Cast(geometry, out rectangle)) { if (rectangle.FillContainsWithDetail(geomDisplay) == detail) { return(true); } } } else if (brush != null && drawing.Geometry.FillContainsWithDetail(geomDisplay) == detail) { return(true); } return(false); }