所以我在Visual Layer
上画了几行并将其添加到Canvas
。现在,我试图HitTest他们,我得到了整个视觉。我怎样才能获得我点击的那一行?
public class MyDrawing : DrawingVisual
{
public MyDrawing ()
{
using (var dc = RenderOpen())
{
foreach (var block in blocks)
{
// Draw lines here
}
}
}
}
private void OnMouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
var x = MousePos.RightDown.X;
var y = MousePos.RightDown.Y;
var hitRect = new Rect(x - 2, y - 2, 4, 4);
VisualTreeHelper.HitTest(MyCanvas, null, MyCallback,
new GeometryHitTestParameters(new RectangleGeometry(hitRect)));
VisualTreeHelper.HitTest(zones, null, MyCallback,
new GeometryHitTestParameters(new RectangleGeometry(hitRect)));
}
private static HitTestResultBehavior MyCallback(HitTestResult result)
{
// I want to get the line I have hit here
return HitTestResultBehavior.Stop;
}