public void RecreateGrid(Test.TestData testData) // перегенерировать сетку { foreach (Button btn in testData.testGrid.Children) { btn.Content = testData.NumberToFind(); btn.Background = Brushes.Transparent; } }
public void CreateGrid(Test.TestData testData) { // скрыть сетку с тестом и кнопку "готово" до начала теста testData.testGrid.Visibility = Visibility.Hidden; for (int i = 0; i < testData.numCols; i++) { testData.testGrid.ColumnDefinitions.Add(new ColumnDefinition()); } for (int i = 0; i < testData.numRows; i++) { testData.testGrid.RowDefinitions.Add(new RowDefinition()); } // определяем длину и ширину ячеек foreach (var g in testData.testGrid.RowDefinitions) { g.Height = new GridLength(22); } foreach (var g in testData.testGrid.ColumnDefinitions) { g.Width = new GridLength(22); } for (int i = 0; i < testData.cellCount; i++) { Button button = new Button(); int idx = testData.testGrid.Children.Add(button); button = testData.testGrid.Children[idx] as Button; button.FontSize = 20; button.Content = testData.NumberToFind(); // надпись на кнопке будет от 0 до 9 button.Foreground = Brushes.Black; button.FontWeight = FontWeights.Light; button.Margin = new Thickness(0); button.Padding = new Thickness(0); button.BorderThickness = new Thickness(0); button.Click += Button_Click; button.SetValue(Grid.RowProperty, i / testData.numCols); button.SetValue(Grid.ColumnProperty, i % testData.numCols); button.HorizontalAlignment = HorizontalAlignment.Center; button.VerticalAlignment = VerticalAlignment.Center; button.Background = Brushes.Transparent; } }