我完全厌倦了为路径图添加Rectangle
。下面是我尝试过的代码,但它不能正确地生成Rectangle
:
PathGeometry geom = new PathGeometry();
Geometry g = new RectangleGeometry(myrectangel);
geom.AddGeometry(g);
PathFigureCollection collection = geom.Figures;
pathfigure = collection[0];
还有其他办法吗?
答案 0 :(得分:5)
您可以使用GeometryGroup组合几何。 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;