First, please understand that all controls are added "dynamically". XAML only helps to automate creation of the window setup, but behind the scene all is done dynamically, during run time.
The main problem here is to setup row and column of the button in the grid. The unusual feature which makes WPF different from other UI libraries is using
dependency properties, see
http://msdn.microsoft.com/en-us/library/ms752914.aspx[
^].
Button AddButton(string caption, int row, int column, Grid parent) {
Button button = new Button();
button.Content = caption;
parent.Children.Add(button);
Grid.SetRow(button, row);
Grid.SetColumn(button, column);
return button;
}
Just call a method like this in a double cycle (by rows and columns).
I should also note that having so many buttons is a sign of the problem of your design. You can use a variant suggested by Nishant. There can be different designs, based on
TreeView
which nodes define required action, so the can be structured hierarchically.
—SA