private bool HitTestDrawing(GeometryDrawing drawing, Point pt) { Pen pen = drawing.Pen; Brush brush = drawing.Brush; if (pen != null && brush == null) { if (drawing.Geometry.StrokeContains(pen, pt)) { return true; } else { Geometry geometry = drawing.Geometry; EllipseGeometry ellipse = null; RectangleGeometry rectangle = null; PathGeometry path = null; if (TryCast.Cast(geometry, out ellipse)) { if (ellipse.FillContains(pt)) { return true; } } else if (TryCast.Cast(geometry, out rectangle)) { if (rectangle.FillContains(pt)) { return true; } } else if (TryCast.Cast(geometry, out path)) { PathFigureCollection pathFigures = path.Figures; int itemCount = pathFigures.Count; if (itemCount == 1) { if (pathFigures[0].IsClosed && path.FillContains(pt)) { 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.FillContains(pt)) { return true; } } } } } } } else if (brush != null && drawing.Geometry.FillContains(pt)) { return true; } return false; }