for (int i = 0; i < 5; i++)
{
LayoutRoot.ColumnDefinitions.Add(
new ColumnDefinition()); // *
//new ColumnDefinition() { Width = GridLength.Auto }); // Auto
//new ColumnDefinition() { Width = new GridLength(double.NaN, GridUnitType.Star) }); *
//new ColumnDefinition() { Width = new GridLength(0.1, GridUnitType.Star) }); // 0.1*
//new ColumnDefinition() { Width = new GridLength(100) }); // 100
}
for (int i = 0; i < 5; i++)
{
LayoutRoot.RowDefinitions.Add(
new RowDefinition()); // *
}
LayoutRoot.ShowGridLines = true;
// create a image
GeometryGroup ellipses = new GeometryGroup();
ellipses.Children.Add(new EllipseGeometry(new Point(40, 40), 20, 30));
ellipses.Children.Add(new EllipseGeometry(new Point(40, 40), 30, 20));
GeometryDrawing geo = new GeometryDrawing();
geo.Geometry = ellipses;
geo.Brush = Brushes.Brown;
geo.Pen = new Pen(Brushes.Black, 2);
DrawingImage image = new DrawingImage(geo);
image.Freeze();
Image[,] images = new Image[5, 5];
for (int row = 0; row < 5; row++)
{
for (int col = 0; col < 5; col++)
{
images[col, row] = new Image();
images[col, row].Source = image;
images[col, row].SetValue(Grid.ColumnProperty, col);
images[col, row].SetValue(Grid.RowProperty, row);
LayoutRoot.Children.Add(images[col, row]);
}
}