4

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?

Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
Uthistran Selvaraj.
  • 558
  • 2
  • 11
  • 29

1 Answers1

6

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;
Nitesh
  • 7,261
  • 3
  • 30
  • 25