private void SetupThePuzzleGridStructure() { _puzzleLogic = new PuzzleLogic(_numRows); // Define rows and columns in the Grid for (int row = 0; row < _numRows; row++) { RowDefinition r = new RowDefinition(); r.Height = GridLength.Auto; this.RowDefinitions.Add(r); ColumnDefinition c = new ColumnDefinition(); c.Width = GridLength.Auto; this.ColumnDefinitions.Add(c); } Style buttonStyle = (Style)this.Resources["PuzzleButtonStyle"]; // Now add the buttons in int i = 1; for (int row = 0; row < _numRows; row++) { for (int col = 0; col < _numRows; col++) { // lower right cell is empty if (_numRows != 1 && row == _numRows - 1 && col == _numRows - 1) { continue; } Button b = new Button(); b.FontSize = 24; // Styling comes in only here... if (_styling) { b.Style = buttonStyle; } b.SetValue(Grid.RowProperty, row); b.SetValue(Grid.ColumnProperty, col); b.Content = i.ToString(); i++; this.Children.Add(b); } } }