#483 – InkCanvas MinHeight and MinWidth

If you don’t give an InkCanvas an explicit Height or Width, but leave both to default to Auto, the InkCanvas automatically sets its MinHeight property to 250 and its MinWidth to 350.  This is done using a trigger, created in the constructor of the InkCanvas.

This can be confusing, since the same is not true for the Canvas control, whose MinHeight and MinWidth properties are initially set to 0.0.

Below, we include an InkCanvas control in a window and attach a button at each corner, so that we can better see its boundaries.  The InkCanvas sizes to fit its container (the Window), but you can see that a minimum height and width has been set.

        <Button Content="Bottom Left" InkCanvas.Bottom="5" InkCanvas.Left="5"/>
        <Button Content="Bottom Right" InkCanvas.Bottom="5" InkCanvas.Right="5"/>
        <Button Content="Top Right" InkCanvas.Top="5" InkCanvas.Right="5"/>
        <Button Content="Top Left" InkCanvas.Top="5" InkCanvas.Left="5"/>

To allow the InkCanvas to size freely, set MinHeight and MinWidth to 0.0.


#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">
    		<RowDefinition Height="Auto"/>
    		<RowDefinition Height="Auto"/>
    		<RowDefinition Height="Auto"/>
    		<RowDefinition Height="Auto"/>
            <ColumnDefinition Width="Auto" MinWidth="100"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="1*" MinWidth="50"/>

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.

#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.

	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.

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