FrameworkElement.Height 屬性


取得或設定項目的建議高度。Gets or sets the suggested height of the element.

 property double Height { double get(); void set(double value); };
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
public double Height { get; set; }
member this.Height : double with get, set
Public Property Height As Double


項目的高度 (以 裝置獨立單位 (每單位 1/96 英吋)device-independent units (1/96th inch per unit) 為單位)。The height of the element, in 裝置獨立單位 (每單位 1/96 英吋)device-independent units (1/96th inch per unit). 預設值是 NaNThe default value is NaN. 這個值必須等於或大於 0.0。This value must be equal to or greater than 0.0.



Height 是指定高度資訊 FrameworkElement 上三個可寫入屬性的其中一個。Height is one of three writable properties on FrameworkElement that specify height information. 另外兩個 MinHeightMaxHeightThe other two are MinHeight and MaxHeight. 如果這些值之間有衝突,實際高度判斷的應用程式順序是必須接受第一個 MinHeight,然後 MaxHeight,最後,如果它是在界限內,則 HeightIf 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.

如果這個專案是某個其他專案中的子專案,則將此屬性設定為值其實只是建議的值。If this element is a child element within some other element, then setting this property to a value is really only a suggested value. 配置系統以及父元素的特定配置邏輯,會在配置處理期間使用此值做為非系結輸入。The layout system as well as the particular layout logic of the parent element will use the value as a nonbinding input during the layout process. 實際上,FrameworkElement 幾乎一律是其他專案的子項目;即使您在 Window上設定 HeightIn practical terms, a FrameworkElement is almost always the child element of something else; even when you set the Height on Window. (若為 Window,當基礎應用程式模型建立可建立裝載應用程式之 Hwnd 的基本轉譯假設時,就會使用該值。)(For Window, that value is used when the underlying application model establishes the basic rendering assumptions that create the Hwnd that hosts the application.)

除了可接受的 Double 值之外,也可以 Double.NaN此屬性。In addition to acceptable Double values, this property can also be Double.NaN. 這是您在程式碼中指定自動調整大小行為的方式。This is how you specify auto sizing behavior in code. XAMLXAML 您會將值設定為字串 "Auto" (不區分大小寫),以啟用自動調整大小行為。In XAMLXAML you set the value to the string "Auto" (case insensitive) to enable the auto sizing behavior. 自動調整大小行為意指元素會填滿其可用的高度。Auto sizing behavior implies that the element will fill the height available to it. 但請注意,特定控制項通常會透過預設的主題樣式提供預設值,除非特別重新啟用,否則會停用自動調整大小行為。Note however that specific controls frequently supply default values through their default theme styles that will disable the auto sizing behavior unless it is specifically re-enabled.

這個屬性的傳回值一律與任何已設定的值相同。The return value of this property is always the same as any value that was set to it. 相較之下,ActualHeight 的值可能會有所不同。In contrast, the value of the ActualHeight may vary. 這可能是靜態的,因為配置因某種原因而拒絕建議的大小,或暫時發生。This can happen either statically because the layout rejected the suggested size for some reason, or momentarily. 版面配置系統本身會以非同步方式運作,相對於屬性系統的一組 Height,而且可能尚未處理過特定的大小調整屬性變更。The layout system itself works asynchronously relative to the property system's set of Height and may not have processed that particular sizing property change yet.

ValidateValueCallback 機制會強制執行 Double 值的值限制。The value restrictions on the Double value are enforced by a ValidateValueCallback mechanism. 如果您嘗試設定不正確值,則會擲回執行時間例外狀況。If you attempt to set an invalid value, a run-time exception is thrown.

除了驗證檢查之外,配置系統強制執行的 Height (這是非常大的數位,大於 Single.MaxValue,但小於 Double.MaxValue),會有不確定性的上限值。In addition to the validation check, there is a nondeterministic upper value bound for Height that is enforced by the layout system (this is a very large number, larger than Single.MaxValue but smaller than Double.MaxValue). 如果您超出此界限,將不會轉譯元素,也不會擲回任何例外狀況。If you exceed this bound, the element will not render, and no exception is thrown. 請勿將 Height 設定為明顯大於任何可能視覺效果顯示大小上限的值,或者您可能會超過此不具決定性的上限。Do not set Height to a value that is significantly larger than the maximum size of any possible visual display, or you may exceed this nondeterministic upper bound.

XAML Attribute UsageXAML Attribute Usage

<object Height="double"/>  


<object Height="qualifiedDouble"/>  


<object Height="Auto"/>  



Double 值的字串表示,等於或大於0.0。String representation of a Double value equal to or greater than 0.0. 如需上限資訊,請參閱<備註>。See Remarks for upper bound information. 這個值會解讀為 裝置獨立單位 (1/96 英吋)device-independent unit (1/96th inch) 度量。This value is interpreted as a 裝置獨立單位 (1/96 英吋)device-independent unit (1/96th inch) measurement. 字串不需要明確包含小數點。Strings need not explicitly include decimal points. 比方說,1 的值是可接受的。For instance a value of 1 is acceptable.

如上所述的double值,後面接著下列其中一個單元宣告字串: pxincmptA double value as described above, followed by one of the following unit declaration strings: px, in, cm, pt.

px (預設值)為 裝置獨立單位 (每單位 1/96 英吋)device-independent units (1/96th inch per unit)px (default) is 裝置獨立單位 (每單位 1/96 英吋)device-independent units (1/96th inch per unit)

in 為英寸;1in = = 96pxin is inches; 1in==96px

cm 為釐米;1cm = = (96/2.54) pxcm is centimeters; 1cm==(96/2.54) px

pt 為點;1pt = = (96/72) pxpt is points; 1pt==(96/72) px

啟用自動調整大小行為。Enables autosizing behavior. 請參閱<備註>。See Remarks.

相依性屬性資訊Dependency Property Information

識別碼欄位Identifier field HeightProperty
設定為 true 的中繼資料屬性Metadata properties set to true AffectsMeasure