I have a simple grid layout which is just hosting several labels and textboxes. Labels in the first column, boxes in the second.
Whenever I add a new box, I have to add an empty <RowDefinition /> in to my <Grid.RowDefinitions> block to allow it to occupy a new row. Since I don't have any style attached to these rows, is there some sort of shorthand that would prevent having to to this?
<Grid.ColumnDefinitions>
<ColumnDefinition Width="65" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
You could use an Attached Property to create a shorthand syntax on your own.
I've created a sample here: https://github.com/thomasclaudiushuber/Wpf-Grid-Extensions
It allows you to write this:
<Grid local:GridExtensions.Structure="*,100|200,*">
</Grid>
And behind the scenes it creates this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="100"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
</Grid>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With