2012-05-09 1 views
0

に2つのUIElements(矩形)とその座標があります。どのようにコードの後ろに円弧でそれらを接続することができますか?2つのUIElementを弧で接続する

+0

私はgoogleを使用していますが、私は何か有用なものを見つけることができませんでした。私はArcSegmentを作成しようとしましたが、成功しませんでした。 ArcSegment arc = new ArcSegment(x1、y1、x2、y2); – Bip

答えて

2

矩形(または他のオブジェクト)に正確なヒットを得る必要はありません:Zの順序が正しいことを確認してください。 arc.SetValue(Canvas.ZIndex, -1)はバックグラウンドにプッシュします。垂直ヒットが必要な場合は、代数を打ち消す必要があります。/

円弧(http://msdn.microsoft.com/en-us/library/ms751808.aspxを参照)の場合は、PathFigureに含める必要があります。

編集:これは2つの接続された長方形を示しています。線は単純に2つの中心間を行き来します。弧は1つの中心(pathFigureの開始点)から始まり、最初の引数は2番目のオブジェクトの中心です。

 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); 
+0

2つの他の図形の後ろに線を隠すことはできません。弧は、2つの他のオブジェクトの中心間を移動できます。 z順序付けによって残りの部分が処理されます。 – Nzc

+0

数学はArcオブジェクトに含まれています。 – Nzc

関連する問題