FrameworkElement.MaxHeight property

Applies to Windows and Windows Phone

Gets or sets the maximum height constraint of a FrameworkElement.

Syntax


public:
property double MaxHeight { 
   double get();
   void set (double value);
}


<frameworkElement MaxHeight="double"/>
 

Property value

Type: System.Double [.NET] | float64 [C++]

The maximum height of the object, in pixels. The default value is PositiveInfinity. This value can be any value equal to or greater than 0. PositiveInfinity is also valid.

Remarks

MaxHeight is one of three writable properties on FrameworkElement that specify height information. The other two are Height and Height. If there is a conflict between these values, the order of application for actual height determination is that first MinHeight must be honored, then MaxHeight, and finally, if it is within bounds, Height. All of these properties are recommendations to the layout behavior of the element's parent in the object tree. The height of the object after layout runs is available as the ActualHeight property value.

Examples

This XAML example shows a technique of specifying a MaxHeight for a ViewBox. ViewBox is a decorator that can apply layout information to a single child and divide layout areas for the next parent element (in this case a StackPanel).


<Grid Height="600" Width="600">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="auto" />
        <RowDefinition />
    </Grid.RowDefinitions>
    
    <StackPanel Grid.Row="0" Grid.Column="0" Margin="5,5,5,5" Orientation="Vertical">
        <TextBlock Text="Stretch" FontWeight="Bold" FontSize="12" />
        <Button Name="btn1" Click="stretchNone" Content="None" />
        <Button Name="btn2" Click="stretchFill" Content="Fill" />
        <Button Name="btn3" Click="stretchUni" Content="Uniform" />
        <Button Name="btn4" Click="stretchUniFill" Content="UniformToFill" />
    </StackPanel>

    <StackPanel Grid.Row="0" Grid.Column="1" Margin="5,5,5,5" Orientation="Vertical">
        <TextBlock Text="StretchDirection" FontWeight="Bold" FontSize="12" />
        <Button Name="btn5" Click="sdUpOnly" Content="UpOnly" />
        <Button Name="btn6" Click="sdDownOnly" Content="DownOnly" />
        <Button Name="btn7" Click="sdBoth" Content="Both" />
    </StackPanel>

    <StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="5" 
                Orientation="Vertical">
        <TextBlock Name="txt1" FontSize="12" FontWeight="Bold" />
        <TextBlock Name="txt2" FontSize="12" FontWeight="Bold" />
    </StackPanel>   

    <StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="5" 
                Orientation="Horizontal">
        <Viewbox MaxWidth="100" MaxHeight="100" Name="vb1">
            <Image Source="flower.jpg"/>
        </Viewbox>
        <Viewbox MaxWidth="200" MaxHeight="200" Name="vb2">
            <Image Source="flower.jpg"/>
        </Viewbox>
        
        <Viewbox MaxWidth="300" MaxHeight="300" Name="vb3">
            <Image Source="flower.jpg"/>
        </Viewbox>
    </StackPanel>

</Grid>


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

FrameworkElement
ActualHeight
Height
Height
Quickstart: Defining layouts

 

 

Show:
© 2014 Microsoft. All rights reserved.