4

我完全厌倦了Rectangle在路径图中添加一个。以下是我尝试过的代码,但结果不正确Rectangle

PathGeometry geom = new PathGeometry();
Geometry g = new RectangleGeometry(myrectangel);
geom.AddGeometry(g);

PathFigureCollection collection = geom.Figures;
pathfigure = collection[0];

还有其他方法吗?

4

1 回答 1

6

您可以使用GeometryGroup组合几何。A从一个或多个对象GeometryGroup创建复合几何。Geometry

GeometryGroup gg = new GeometryGroup();            
gg.Children.Add(new RectangleGeometry(new Rect(0, 0, 100, 100)));
gg.Children.Add(new RectangleGeometry(new Rect(100, 100, 100, 100)));
gg.Children.Add(new RectangleGeometry(new Rect(200, 200, 100, 100)));

System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
path.Data = gg;
path.Fill = Brushes.Blue;
于 2013-08-07T04:34:57.543 回答