A Grid
is a grid and the rows and columns are numbered for a specific reason. It's like a piece of graph paper sliced up into a fixed numbers of squares. Because the numbers of rows and columns is fixed you can do powerful things like row and column spanning. Conversely, this is not flexible for a variable number of rows or columns.
If you need a variable number of rows, or you are continually adding rows at design time, then it may be that the Grid
is not the best design element for you. Or better still, you can use the Grid
in combination with another layout element to get the flexibility you need.
For example, you can put all your variable rows into a single Grid
row and now your grid row count doesn't change any more. But then you will need a layout element that supports a variable number of rows to put into that Grid
row. Well, there are a lot of them to choose from but two for example that are useful are StackPanel
and DockPanel
.
The layout element DockPanel
in particular is very powerful for variable numbers of rows or columns, particularly when used as DockPanels
within DockPanels
or other combinations. All you need to handle this layout problem is to subdivide and conquer!
Here's an introduction to DockPanel
: WPF Tutorial: Dock Panel