資訊
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FrameworkElement.MaxHeight 屬性

取得或設定項目的最大高度條件約束 (Constraint)。

命名空間:  System.Windows
組件:  PresentationFramework (在 PresentationFramework.dll 中)
針對 XAML 的 XMLNS: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

[LocalizabilityAttribute(LocalizationCategory.None, Readability = Readability.Unreadable)]
[TypeConverterAttribute(typeof(LengthConverter))]
public double MaxHeight { get; set; }
<object MaxHeight="double"/>
- or –
<object MaxHeight ="qualifiedDouble"/>

XAML 值

double

Double

Double 值的字串表示等於或大於 0.0。 這會解譯為device-independent unit (1/96th inch) 度量。 字串不需明確的包含小數點。 例如,1 是可接受的值。

相同的 Double 範圍限制如同「屬性值」一節所提及的套用限制,不過,若您需要明確地將值設定為 PositiveInfinity,就必須使用 x:Static 標記延伸

qualifiedDouble

如上所述,double 值之後會跟著下列其中一個宣告字串:pxincmpt

px (預設值) 是device-independent units (1/96th inch per unit)

in 是英吋,1in==96px

cm 是公分,1cm==(96/2.54) px

pt 是點,1pt==(96/72) px

屬性值

型別:System.Double
項目的最大高度,以device-independent units (1/96th inch per unit) 為單位。 預設值是 PositiveInfinity 這個值可以是任何等於或大於 0.0 的值。 PositiveInfinity 也是有效的值。

識別項欄位

MaxHeightProperty

中繼資料屬性設為 true

AffectsMeasure

這是 FrameworkElement 的三個屬性中的其中之一,這三個屬性會指定高度資訊。 其他兩種屬性為 MinHeightHeight 如果這些值彼此衝突,實際高度判斷應用的順序如下:您必須先接受 MinHeight,再接受 MaxHeight,最後才是 Height (如果每一個都在界限內)。

Double 值的限制是由 ValidateValueCallback 機制強制規定。 如果您嘗試設定無效的值,便會擲回執行階段例外狀況。

This example visually shows the differences in rendering behavior among the four height-related properties in Windows Presentation Foundation (WPF).

The FrameworkElement class exposes four properties that describe the height characteristics of an element. These four properties can conflict, and when they do, the value that takes precedence is determined as follows: the MinHeight value takes precedence over the MaxHeight value, which in turn takes precedence over the Height value. A fourth property, ActualHeight, is read-only, and reports the actual height as determined by interactions with the layout process.

The following Extensible Application Markup Language (XAML) examples draw a Rectangle element (rect1) as a child of Canvas. You can change the height properties of a Rectangle by using a series of ListBox elements that represent the property values of MinHeight, MaxHeight, and Height. In this manner, the precedence of each property is visually displayed.


<Canvas Height="200" MinWidth="200" Background="#b0c4de" VerticalAlignment="Top"  HorizontalAlignment="Center" Name="myCanvas" Margin="0,0,0,50">
    <Rectangle HorizontalAlignment="Center" Canvas.Top="50" Canvas.Left="50"  Name="rect1" Fill="#4682b4" Height="100" Width="100"/>
</Canvas>


...


    <TextBlock Grid.Row="1" Grid.Column="0" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle Height:</TextBlock>
    <ListBox Grid.Column="1" Grid.Row="1" Margin="10,0,0,0" Height="50" Width="50" SelectionChanged="changeHeight">
      <ListBoxItem>25</ListBoxItem>
      <ListBoxItem>50</ListBoxItem>
      <ListBoxItem>75</ListBoxItem>
      <ListBoxItem>100</ListBoxItem>
      <ListBoxItem>125</ListBoxItem>
      <ListBoxItem>150</ListBoxItem>
      <ListBoxItem>175</ListBoxItem>
      <ListBoxItem>200</ListBoxItem>
    </ListBox>

	<TextBlock Grid.Row="1" Grid.Column="2" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle MinHeight:</TextBlock>
    <ListBox Grid.Column="3" Grid.Row="1" Margin="10,0,0,0" Height="50" Width="50" SelectionChanged="changeMinHeight">
      <ListBoxItem>25</ListBoxItem>
      <ListBoxItem>50</ListBoxItem>
      <ListBoxItem>75</ListBoxItem>
      <ListBoxItem>100</ListBoxItem>
      <ListBoxItem>125</ListBoxItem>
      <ListBoxItem>150</ListBoxItem>
      <ListBoxItem>175</ListBoxItem>
      <ListBoxItem>200</ListBoxItem>
  </ListBox>      

    <TextBlock Grid.Row="1" Grid.Column="4" Margin="10,0,0,0" TextWrapping="Wrap">Set the Rectangle MaxHeight:</TextBlock>
    <ListBox Grid.Column="5" Grid.Row="1" Margin="10,0,0,0" Height="50" Width="50" SelectionChanged="changeMaxHeight">
      <ListBoxItem>25</ListBoxItem>
      <ListBoxItem>50</ListBoxItem>
      <ListBoxItem>75</ListBoxItem>
      <ListBoxItem>100</ListBoxItem>
      <ListBoxItem>125</ListBoxItem>
      <ListBoxItem>150</ListBoxItem>
      <ListBoxItem>175</ListBoxItem>
      <ListBoxItem>200</ListBoxItem> 
    </ListBox>


The following code-behind examples handle the events that the SelectionChanged event raises. Each handler takes the input from the ListBox, parses the value as a Double, and applies the value to the specified height-related property. The height values are also converted to a string and written to various TextBlock elements (definition of those elements is not shown in the selected XAML).


private void changeHeight(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
    Double sz1 = Double.Parse(li.Content.ToString());
    rect1.Height = sz1;
    rect1.UpdateLayout();
    txt1.Text= "ActualHeight is set to " + rect1.ActualHeight;
    txt2.Text= "Height is set to " + rect1.Height;
    txt3.Text= "MinHeight is set to " + rect1.MinHeight;
    txt4.Text= "MaxHeight is set to " + rect1.MaxHeight;
}
private void changeMinHeight(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
    Double sz1 = Double.Parse(li.Content.ToString());
    rect1.MinHeight = sz1;
    rect1.UpdateLayout();
    txt1.Text= "ActualHeight is set to " + rect1.ActualHeight;
    txt2.Text= "Height is set to " + rect1.Height;
    txt3.Text= "MinHeight is set to " + rect1.MinHeight;
    txt4.Text= "MaxHeight is set to " + rect1.MaxHeight;
}
private void changeMaxHeight(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem li = ((sender as ListBox).SelectedItem as ListBoxItem);
    Double sz1 = Double.Parse(li.Content.ToString());
    rect1.MaxHeight = sz1;
    rect1.UpdateLayout();
    txt1.Text= "ActualHeight is set to " + rect1.ActualHeight;
    txt2.Text= "Height is set to " + rect1.Height;
    txt3.Text= "MinHeight is set to " + rect1.MinHeight;
    txt4.Text= "MaxHeight is set to " + rect1.MaxHeight;
}


For the complete sample, see Height Properties Sample.

.NET Framework

支援版本:4、3.5、3.0

.NET Framework Client Profile

支援版本:4、3.5 SP1

Windows 7, Windows Vista SP1 (含) 以後版本, Windows XP SP3, Windows Server 2008 (不支援伺服器核心), Windows Server 2008 R2 (SP1 (含) 以後版本支援伺服器核心), Windows Server 2003 SP2

.NET Framework 並不支援各種平台的所有版本。如需支援的版本的清單,請參閱.NET Framework 系統需求

社群新增項目

顯示:
© 2014 Microsoft