#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 these ads

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 368 other followers

%d bloggers like this: