protected IVisual TestHit(Point p, int hitSize, Func <IVisual, Point, int, bool> hitTest) { if (p == _noHit) { return(null); } if ((Focused != null) && hitTest(Focused, p, hitSize)) { return(Focused); } if ((Hovered != null) && hitTest(Hovered, p, hitSize)) { return(Hovered); } int halfSize = hitSize / 2; var hitBounds = new Rectangle(p.X - halfSize, p.Y - halfSize, hitSize, hitSize); foreach (var visual in SpatialIndex.Query(hitBounds, ZOrder.EdgesFirst)) { if ((visual == Focused) || (visual == Hovered)) { continue; } if (hitTest(visual, p, hitSize)) { return(visual); } } _noHit = p; return(null); }