A flexible, easy to configure replacement for the standard Grid control. Ported from WPF AutoGrid
Now Available on NuGet! https://www.nuget.org/packages/Avalonia.AutoGrid/
AutoGrid lets you reduce the amount of xaml when using grids for layout by allowing you to define rows and columns as simple properties and alleviating you from having to explicitly specify the row and column a child control belongs to.
Partially based on work at http://rachel53461.wordpress.com/2011/09/17/wpf-grids-rowcolumn-count-properties/
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="35" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" />
<TextBox Grid.Row="0" Grid.Column="1" />
<Label Grid.Row="1" Grid.Column="0" />
<TextBox Grid.Row="1" Grid.Column="1" />
</Grid>
<AutoGrid RowCount="2" RowHeight="35" Columns="100,auto">
<Label />
<TextBox />
<Label />
<TextBox />
</AutoGrid>
Notice how in the example above we didn't need to specify the row and column that each element belonged to; AutoGrid automatically figures out what row and column we wanted based on our configuration of the grid. AutoGrid uses a row first or column first arrangement for its auto layout which can changed by setting the Orientation property.
Don't want AutoGrid to position elements automatically? OK
Explicit assignment of columns and rows still works too. This allows you to upgrade more easily. Most of time you can mix both without much trouble, but take care that this is not always the case.
<local:AutoGrid ColumnCount="6" ColumnWidth="*" RowHeight="*" RowCount="6" ChildMargin="10" />
<local:AutoGrid Columns="2*,5*" RowCount="6" RowHeight="25" />
In this example, labels will fall in the first column, and textboxes will be in the second column
<AutoGrid RowCount="2" RowHeight="35" Columns="100,auto">
<Label /> <!-- Col=0, Row=0 -->
<TextBox /> <!-- Col=1, Row=0 -->
<Label /> <!-- Col=0, Row=1 -->
<TextBox /> <!-- Col=1, Row=1 -->
</AutoGrid>
In this example, labels will fall in the first row, and textboxes will be in the second row
<AutoGrid RowCount="2" RowHeight="35" Columns="100,auto" Orientation="Vertical">
<Label /> <!-- Col=0, Row=0 -->
<TextBox /> <!-- Col=0, Row=1 -->
<Label /> <!-- Col=1, Row=0 -->
<TextBox /> <!-- Col=1, Row=1 -->
</AutoGrid>
Collapsed elements will be removed from the flow, hidden elements will still occupy space in the grid
<AutoGrid RowCount="2" RowHeight="35" Columns="100,auto">
<Label /> <!-- Col=0, Row=0 -->
<TextBox /> <!-- Col=1, Row=0 -->
<Label Visibility="Collapsed" />
<TextBox /> <!-- Col=0, Row=1 -->
</AutoGrid>