布局 -连连看:
代码:
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{ //动态创建行
for (int i = ; i < ; i++)
{
//列
ColumnDefinition cl = new ColumnDefinition();
grid.ColumnDefinitions.Add(cl); //列
RowDefinition rd = new RowDefinition();
grid.RowDefinitions.Add(rd);
}
Random random = new Random(); for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
int imgName = random.Next(, );//>=1 & <10的随机数 Image img = new Image();
img.Source = new BitmapImage(new Uri("imgs/"+imgName+".png",UriKind.Relative));
Grid.SetRow(img, i);
Grid.SetColumn(img, j);
grid.Children.Add(img);
}
}
}