我在Canvas
及其座標中有兩個UIElements
(即矩形)。我如何在後面的代碼中將它們與弧連接起來?將兩個UIElement連接到Arc
0
A
回答
2
不需要在矩形(或其他對象)上得到精確的命中:確保Z排序是正確的。 arc.SetValue(Canvas.ZIndex, -1)
會將其推到背景。如果你想要一個垂直命中,你需要打破代數:/
對於弧:(見http://msdn.microsoft.com/en-us/library/ms751808.aspx),它需要被包含在一個PathFigure中。
編輯:這顯示了兩個連接的矩形。這條線簡單地在兩個中心之間運行。弧開始於一箇中心(pathFigure startpoint),第一個參數是第二個對象的中心。
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);
相關問題
- 1. 將兩個XIB連接到一個ViewController
- 2. 將兩個表連接到更多連接到連續的同一個表
- 3. PHP MySQL將兩個表連接到條件連接
- 4. 得到兩個連接表
- 5. 將兩個SELECT連接成一個mysql_query
- 6. 將PHP表格連接到兩個表中的鏈接
- 7. 連接兩個查詢到一個
- 8. 連接兩個Dataframes
- 9. 連接兩個ObjectDataSources
- 10. 連接兩個表
- 11. 連接兩個表
- 12. 連接兩個DB
- 13. 連接兩個data.tables
- 14. 連接兩個dataframes
- 15. 連接兩個表
- 16. 類兩個連接
- 17. 連接兩個表
- 18. 連接兩個表
- 19. 連接兩個表
- 20. 連接兩個表
- 21. 連接兩個類?
- 22. 連接兩個表
- 23. 連接兩個行
- 24. 將兩個表連接到一個的SQL
- 25. 將兩個Facebook應用連接到單個Firebase項目
- 26. 在SQL Server中將兩個表連接到一個表中
- 27. 將兩個數據表連接到一個數據表
- 28. SQL - 將兩個源列連接到一個目標列
- 29. 將兩個數據源連接到同一個數據庫
- 30. 將兩個USB設備連接到一個PC端口
我使用谷歌,我找不到anythin有用。我試圖創建ArcSegment但沒有任何成功。如果有:'ArcSegment arc = new ArcSegment(x1,y1,x2,y2);' – Bip