I've created a griddefinition in my .xaml file.
The size value (_lattice.size) for the grid only emerges at runtime. How can I dynamically fill the grid up with rows and columns and also place buttons in every single cell of the button grid?
My attempt:
//.xaml
<Grid x:FieldModifier="public" x:Name="_tableGrid">
</Grid>
//code-behind file (c#)
private void GenerateTable(string filepath)
{
            GamePage.statusLabel.IsVisible = true;
            GamePage.buttonStartStop.IsVisible = true;
            _initializeTerminate.InitializeGame(filepath, _lattice, _snake, _egg);
            for(Int32 k = 0; k < _lattice.size; k++)
            {
                var r = new RowDefinition();
                r.Height = 50;
                GamePage._tableGrid.RowDefinitions.Add(r);
                
            }
            for(Int32 l = 0; l < _lattice.size; l++)
            {
                var c = new ColumnDefinition();
                c.Width = 50;
                GamePage._tableGrid.ColumnDefinitions.Add(c);
            }
            for (Int32 i = 0; i < _lattice.size; i++)
            {
                
                for (Int32 j = 0; j < _lattice.size; j++)
                {
                    _lattice.button_lattice[j * _lattice.size + i] = new Button();
                    _lattice.button_lattice[j * _lattice.size + i].Background = Brush.White;
                    _lattice.button_lattice[j * _lattice.size + i].BorderWidth = 1.0;
                    _lattice.button_lattice[j * _lattice.size + i].BorderColor = Color.Yellow;
                 GamePage._tableGrid.Children.Add(_lattice.button_lattice[j * _lattice.size + i]);
                    
                }
            }
}
Unfortunately, the above code does not generate the desired behaviour. It seems that there is only a single button present on the screen.