Question

I am self-training myself in WPF. I am using a Canvas to have two polygons grouped together:

var grp = new Canvas();

var polygon = new new Polygon();
polygon.Points.Add(new Point(-15, -20));
polygon.Points.Add(new Point(0, 20));
polygon.Points.Add(new Point(15, -20));
polygon.StrokeThickness = 1;
polygon.Stroke = Brushes.Violet;
polygon.Fill = Brushes.Yellow;

var rotationCenter = centroid(polygon);

var centerPoint = new Ellipse();
Canvas.SetLeft(centerPoint, rotationCenter.X -1 );
Canvas.SetTop(centerPoint, rotationCenter.Y-1);
centerPoint.Fill = Brushes.Green;
centerPoint.Height = 3;
centerPoint.Width = 3;

grp.Children.Add(shipPolygon);
grp.Children.Add(centerPoint);

Then, I move, rotate and play with my grouped polygons using the grp Canvas.

Because I don't want to use my Canvas for anything else than grouping polygons each other, I wonder if it exists something lighter than a Canvas to do this.

I searched for something equivalent of Model3DGroup in WPF3D to group UIElements in WPF2D, but without success.

Is Canvas the lightest container to group UIElements ?

Was it helpful?

Solution

What you mean with grouping is actually called layouting in wpf. you pick a container which layouts your children.

Yes canvas is the most stupid container and so its the most lightest. grid has columns and rows which is very smart and stackpanel stacks its children depending on ortientation but canvas doesn't do anything except place uielements depending on x and y values.

Therefore I think canvas is pretty fine for your example since you want to have a bit of offset before you want to draw your figures.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top