FrameworkElement.MaxHeight 屬性

定義

取得或設定 FrameworkElement的最大高度條件約束。

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

void MaxHeight(double value);
public double MaxHeight { get; set; }
var double = frameworkElement.maxHeight;
frameworkElement.maxHeight = double;
Public Property MaxHeight As Double
<frameworkElement MaxHeight="double"/>
 

屬性值

Double

double

物件的最大高度,以圖元為單位。 預設值為 PositiveInfinity。 這個值可以是等於或大於 0 的任何值。 PositiveInfinity 也有效。

範例

這個 XAML 範例示範指定ViewBox的 技術 MaxHeightViewBox 是裝飾專案,可將配置資訊套用至單一子系,並將下一個父元素的配置區域分割 (在此情況下 為 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>

備註

MaxHeightFrameworkElement 上指定高度資訊的三個可寫入屬性之一。 其他兩個是 HeightMinHeight。 如果這些值之間發生衝突,則實際高度判斷的應用程式順序是必須接受第一個 MinHeight ,如果是 MaxHeight 在界限內,則為 ,最後為 Height。 所有這些屬性都是物件樹狀結構中元素父系的配置行為建議。 版面配置執行之後物件的高度可做為 ActualHeight 屬性值。

元素的最終 ActualHeight 可能超過 MaxHeight 。 例如,如果 UseLayoutRounding 設定為 true ,且您的應用程式在解析度 縮放 比例大於 100% 的顯示器上執行, 則 ActualHeight 可能會四捨五入,以協助確保您的 UI 在縮放時不會模糊。

適用於

另請參閱