动态生成:
4.动态生成类:
TextBlock tb = new TextBlock();
tb.Text = "姓名";
tb.FontSize = 30;
Grid.SetRow(tb, 1);
Grid.SetColumn(tb, 0);
grid1.Children.Add(tb);
TextBlock tb1 = new TextBlock();
tb1.Text = "手机";
tb1.FontSize = 30;
Grid.SetRow(tb1, 0);
Grid.SetColumn(tb1, 1);
grid1.Children.Add(tb1);
5.动态生成行和列:
for (int i = 0; i < 10; i++)
{
RowDefinition row = new RowDefinition();
//row.Height = new GridLength(50);
row.Height = GridLength.Auto;
grid1.RowDefinitions.Add(row);
}
for (int i = 0; i < 8; i++)
{
ColumnDefinition col = new ColumnDefinition();
col.Width = GridLength.Auto;
grid1.ColumnDefinitions.Add(col);
}
动态生成图片
for (int row = 0; row < 10;row++ )
{
for (int col = 0; col < 8;col++ )
{
Image img = new Image();
string filename = "ms-appx:///images/" + rd.Next(1,9)+".jpg";
img.Source = new BitmapImage(new Uri(filename));
Grid.SetRow(img,row);
Grid.SetColumn(img,col);
grid1.Children.Add(img);
}
}
}