using the code below I have been able to succesfully populate the grid with Buttons. However, each button is butted right up to the next one. Is there a way to put a magin in between. I know how to do it Xaml, but how do you do it in the code behind?

Dave Thomasberger 21 Reputation points
2022-02-27T18:09:06.023+00:00
    private void PopulateGroup()
    {
        int buttonSize = ((int)(group_Button.MinHeight / myBoard.Size));

        group_Button.Height = group_Button.Width;

        for (int i = 1; i < myBoard.Size; i++)
        {
            for (int j = 1; j < myBoard.Size; j++)
            {
                Button b = new Button();
                b.Content = string.Format("Row: {0}, Column: {1}", i, j);
                Grid.SetRow(b, i);
                Grid.SetColumn(b, j);                    
                grid.Children.Add(b);                    
            }
        }

    }
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,689 questions
0 comments No comments
{count} votes

0 additional answers

Sort by: Most helpful