I was totally tired of adding a Rectangle to a path figure. Below was my tried code, but it does not results correctly as a Rectangle:

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

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

Is there any other way?

有帮助吗?

解决方案

You can combined geometries using a GeometryGroup. A GeometryGroup creates a composite geometry from one or more Geometry objects.

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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top