I have a WPF Grid with a XAML similar to this:
<Grid width=200 Height=200 >
<Grid.ColumnDefinitions >
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" MinHeight="24" />
</Grid.RowDefinitions>
<TextBlock Text="Name" Grid.Row="0" Grid.Column="0"/>
<TextBox Grid.Row="0" Grid.Column="1" />
<TextBlock Text="Age" Grid.Row="1" Grid.Column="0"/>
<TextBox Grid.Row="1" Grid.Column="1" />
</Grid>
I need to add a new row in between existing 2 rows of data, but my worry is that when I add a new row, I will need to manually update Grid.Row attached property in each of the controls that appear in rows below the newly added row.
Is there a smarter way of doing this? may be to set Row/Column numbers relative to adjacent Rows/Columns ?
Cheers.
This problem has been addressed in the Visual Studio 2010 through the Design-Time Row and Column Manipulation Features.
Not needed to manually update Row and Column numbers manually any more as this is taken care of by Visual Studio.
Below demo illustrates this nicely.
http://www.silverlight.net/learn/creating-ui/layout,-rendering,-and-panels/grid-control-design-time-row-and-column-manipulation-features