#422 – Setting Minimum Height and Width on Rows and Columns in a Grid

You can set a minimum height for a row in a Grid using the MinHeight property.  You can also set the minimum width of a column using the MinWidth property.

In the example below, we set the minimum height of the first column, even though its Width is also set to Auto.  We also set the minimum of the 4th column, whose width is set to 1* (the same width as the 3rd column).

    <Grid ShowGridLines="True">
    	<Grid.RowDefinitions>
    		<RowDefinition Height="Auto"/>
    		<RowDefinition Height="Auto"/>
    		<RowDefinition Height="Auto"/>
    		<RowDefinition Height="Auto"/>
    	</Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" MinWidth="100"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*" MinWidth="50"/>
        </Grid.ColumnDefinitions>

When the application starts, the first column is already wider than its elements, because of its minimum width.  The 4th column is set to the same width as the 3rd, both of which are larger than the 4th column’s minimum width.

As we make the window narrower, the 4th column eventually reaches its minimum width and will not become any narrower.

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

3 Responses to #422 – Setting Minimum Height and Width on Rows and Columns in a Grid

  1. Pingback: Dew Drop – November 3, 2011 | Alvin Ashcraft's Morning Dew

  2. Pingback: #423 – Setting Maximum Height and Width for Rows and Columns in a Grid « 2,000 Things You Should Know About WPF

  3. Pingback: #429 – Child Element Properties that Affect Layout « 2,000 Things You Should Know About WPF

Leave a comment