#423 – Setting Maximum Height and Width for Rows and Columns in a Grid

In the same way that you can set minimum height and width of rows and columns in a Grid, you can also set the maximum height or width.

You set the maximum height of a row in a Grid using the MaxHeight property of a RowDefinition element.  You set the maximum width of a column by using the MaxWidth property of a ColumnDefinition element.

    <Grid ShowGridLines="True">
    	<Grid.RowDefinitions>
    		<RowDefinition Height="Auto" />
    		<RowDefinition Height="Auto"/>
    		<RowDefinition Height="Auto"/>
    		<RowDefinition Height="Auto"/>
    	</Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" MaxWidth="20"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*" MaxWidth="80"/>
        </Grid.ColumnDefinitions>


Advertisement

#270 – Minimum and Maximum Window Size

By default, there are no upper or lower limits for the size of a window in WPF–you can shrink a window to the point where none of its content is visible and you can maximize a window so that it takes up the entire desktop.

You can use the MinWidth and MinHeight properties to dictate the minimum dimensions for the window.  When resizing the window, you’ll be unable to make the window any smaller.

<Window
	Width="400" Height="300" MinHeight="100" MinWidth="200">


You can use the MaxWidth and MaxHeight properties to dictate the maximum dimensions for the window.  When resizing the window, you’ll be unable to make the window any larger.  If you try maximizing the window, it will be constrained to the maximum size.

<Window
	Width="400" Height="300" MaxWidth="500" MaxHeight="320">