C# 用圆弧连接两个单元

C# 用圆弧连接两个单元,c#,wpf,silverlight,xaml,uielement,C#,Wpf,Silverlight,Xaml,Uielement,我在画布中有两个ui元素(即矩形)及其坐标。如何将它们与代码隐藏中的arc连接?无需精确点击矩形(或其他对象):确保Z顺序正确arc.SetValue(Canvas.ZIndex,-1)将其推送到后台。如果你想要一个垂直打击,你需要打破代数:/ 对于圆弧:(请参见),它需要包含在路径图中 编辑:显示两个连接的矩形。这条简单的线在两个中心之间运行。圆弧从一个中心(pathFigure起始点)开始,第一个参数是第二个对象的中心 r1 = new Rectangle();

我在
画布中有两个
ui元素
(即矩形)及其坐标。如何将它们与代码隐藏中的arc连接?

无需精确点击矩形(或其他对象):确保Z顺序正确
arc.SetValue(Canvas.ZIndex,-1)
将其推送到后台。如果你想要一个垂直打击,你需要打破代数:/

对于圆弧:(请参见),它需要包含在路径图中

编辑:显示两个连接的矩形。这条简单的线在两个中心之间运行。圆弧从一个中心(pathFigure起始点)开始,第一个参数是第二个对象的中心

        r1 = new Rectangle();
        r1.Margin = new Thickness(50, 50, 0, 0);
        r1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
        r1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
        r1.Height = 50;
        r1.Width= 50;
        r1.Fill = new SolidColorBrush(Colors.Red);


        r2 = new Rectangle();
        r2.Width = 50;
        r2.Height = 50;
        r2.Fill = new SolidColorBrush(Colors.Blue);
        r2.Margin = new Thickness(350, 450, 0, 0);
        r2.VerticalAlignment = System.Windows.VerticalAlignment.Top;
        r2.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;

        l = new Line();
        l.X1 = 75;
        l.Y1 = 75;
        l.X2 = 375;
        l.Y2 = 475;
        l.Fill = new SolidColorBrush(Colors.Purple);
        l.Stroke = new SolidColorBrush(Colors.Purple);
        l.StrokeThickness = 2;
        l.SetValue(Canvas.ZIndexProperty, -1);

        PathGeometry myPathGeometry = new PathGeometry();

        // Create a figure.
        PathFigure pathFigure1 = new PathFigure();
        pathFigure1.StartPoint = new Point(75, 75);

        pathFigure1.Segments.Add(
            new ArcSegment(
                new Point(375, 475),
                new Size(50, 50),
                45,
                true, /* IsLargeArc */
                SweepDirection.Clockwise,
                true /* IsStroked */ ));
        myPathGeometry.Figures.Add(pathFigure1);

        // Display the PathGeometry. 
        Path myPath = new Path();
        myPath.Stroke = Brushes.Black;

        myPath.StrokeThickness = 1;
        myPath.Data = myPathGeometry;
        myPath.SetValue(Canvas.ZIndexProperty, -1);

        LayoutRoot.Children.Add(r1);
        LayoutRoot.Children.Add(r2);
        LayoutRoot.Children.Add(l);
        LayoutRoot.Children.Add(myPath);

我使用谷歌,却找不到任何有用的东西。我试图创建ArcSegment,但没有成功。最好有:
ArcSegment弧=新的ArcSegment(x1,y1,x2,y2)如果将线隐藏在其他两个形状后面,则不会。圆弧可以在其他两个对象的中心之间运行。z排序处理其余部分。数学包含在Arc对象中。