Chuanzhi podcast-XAML Layout-continuous View Interface (little white content), smart podcast-xaml
A simple 10*10 link, with 100 grids, you can use ColumnDefinition and RowDefinition to write 10 groups in the XAML, but the efficiency will be very slow. Therefore, it can be dynamically generated.
public void FG() { Random ran = new Random(); for (int i = 0; i < 10; i++) { ColumnDefinition cDef = new ColumnDefinition(); GridGame.ColumnDefinitions.Add(cDef); RowDefinition rDef = new RowDefinition(); GridGame.RowDefinitions.Add(rDef); } for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { int ImageName = ran.Next(1, 10); Image img = new Image(); img.Source = new BitmapImage(new Uri("Image/"+ImageName+".png", UriKind.Relative)); Grid.SetRow(img, i); Grid.SetColumn(img, j); GridGame.Children.Add(img); } } }
The learning content here is the Grid in XAML. row and Grid. column is an additional attribute and cannot be passed in the CS file. to achieve this, you need to use Grid. setRow and Grid. setColumn.
Note: The Next attribute of Random is greater than or equal to the value on the left. <The value on the right, that is, it does not contain the value on the right, or the value on the left.