当许多绘图在一个视觉中时获取HitTesting结果

时间:2014-09-09 23:03:07

标签: c# wpf hittest

所以我在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;
    }

0 个答案:

没有答案