Skip to main content

UniformGrid

The UniformGrid divides available space evenly into cells. You can specify how many divisions to use, and these can be different in either direction.

Useful Properties

You will probably use these properties most often:

PropertyDescription
RowsInteger. Sets the number of equal rows in the height.
ColumnsInteger. Sets the number of equal columns in the width

Example

<UniformGrid xmlns="https://github.com/avaloniaui"
             Rows="1" Columns="3"
             ColumnSpacing="10"
             Margin="20">
    <Rectangle Fill="Navy" />
    <Rectangle Fill="White" />
    <Rectangle Fill="Red" />
</UniformGrid>
Preview
Loading Avalonia Preview...

Defining a UniformGrid in code

The following example demonstrates how to define and use a UniformGrid with 3 rows and 4 columns and adds 12 rectangles as child elements. Each Rectangle is automatically assigned to a cell in the grid in the order they were added.

<UniformGrid Rows="3" Columns="4">
<Rectangle Width="50" Height="50" Fill="#330000"/>
<Rectangle Width="50" Height="50" Fill="#660000"/>
<Rectangle Width="50" Height="50" Fill="#990000"/>
<Rectangle Width="50" Height="50" Fill="#CC0000"/>
<Rectangle Width="50" Height="50" Fill="#FF0000"/>
<Rectangle Width="50" Height="50" Fill="#FF3300"/>
<Rectangle Width="50" Height="50" Fill="#FF6600"/>
<Rectangle Width="50" Height="50" Fill="#FF9900"/>
<Rectangle Width="50" Height="50" Fill="#FFCC00"/>
<Rectangle Width="50" Height="50" Fill="#FFFF00"/>
<Rectangle Width="50" Height="50" Fill="#FFFF33"/>
<Rectangle Width="50" Height="50" Fill="#FFFF66"/>
</UniformGrid>

More Information

info

For the complete API documentation about this control, see here.

info

View the source code on GitHub UniformGrid.cs

Discussion

Have questions or feedback? Join the conversation below.