#472 – UniformGrid Defaults to Being Square

You typically set the number of rows and columns for a UniformGrid using the Rows and Columns properties.  You can also omit these properties and the UniformGrid will set the number of rows and columns based on the number of child elements.

The UniformGrid will attempt to create a square layout by automatically setting the number of rows and columns as listed below:

  • 1 element – 1 row, 1 column
  • 2-4 elements – 2 rows, 2 columns
  • 5-9 elements – 3 rows, 3 columns
  • 10-16 elements – 4 rows, 4 columns
  • Etc.

Notice that the UniformGrid in this situation will always have the same number of rows as columns.

    <UniformGrid>   <!-- No Rows/Columns specified -->
        <Label Content="1st" Background="AliceBlue" />
        <!-- Etc -->
    </UniformGrid>
</UniformGrid>





Advertisements