private void Button_Click(object sender, RoutedEventArgs e) { LifeGrid.RowDefinitions.Clear(); LifeGrid.ColumnDefinitions.Clear(); LifeGrid.Children.Clear(); int gridWidth = System.Convert.ToInt32(widthBox.Text); int gridHeight = System.Convert.ToInt32(heightBox.Text); for (int i = 0; i < gridHeight / 5; i++) { RowDefinition row = new RowDefinition(); LifeGrid.RowDefinitions.Add(row); } for (int i = 0; i < gridWidth / 5; i++) { ColumnDefinition column = new ColumnDefinition(); LifeGrid.ColumnDefinitions.Add(column); } LifeGrid.Width = gridWidth; LifeGrid.Height = gridHeight; for (int row = 0; row < LifeGrid.RowDefinitions.Count; row++) { for (int column = 0; column < LifeGrid.ColumnDefinitions.Count; column++) { Cell cell = new Cell(row, column, false) { Width = LifeGrid.Width / LifeGrid.ColumnDefinitions.Count, Height = LifeGrid.Height / LifeGrid.RowDefinitions.Count }; cell.SetValue(Grid.ColumnProperty, column); cell.SetValue(Grid.RowProperty, row); cell.Opacity = 0; LifeGrid.Children.Add(cell); } } }
public MainWindow() { InitializeComponent(); LifeGrid.RowDefinitions.Clear(); LifeGrid.ColumnDefinitions.Clear(); LifeGrid.Children.Clear(); int gridWidth = 600; int gridHeight = 600; for (int i = 0; i < gridHeight / 5; i++) { RowDefinition row = new RowDefinition(); LifeGrid.RowDefinitions.Add(row); } for (int i = 0; i < gridWidth / 5; i++) { ColumnDefinition column = new ColumnDefinition(); LifeGrid.ColumnDefinitions.Add(column); } for (int row = 0; row < LifeGrid.RowDefinitions.Count; row++) { for (int column = 0; column < LifeGrid.ColumnDefinitions.Count; column++) { Cell cell = new Cell(row, column, false) { Width = LifeGrid.Width / LifeGrid.ColumnDefinitions.Count, Height = LifeGrid.Height / LifeGrid.RowDefinitions.Count }; cell.SetValue(Grid.ColumnProperty, column); cell.SetValue(Grid.RowProperty, row); cell.Opacity = 0; LifeGrid.Children.Add(cell); } } }