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上设置 Height 也是如此。In 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.

Double 值的值限制由 ValidateValueCallback 机制强制执行。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 属性用法XAML Attribute Usage

<object Height="double"/>  

- 或 --or-

<object Height="qualifiedDouble"/>  

- 或 --or-

<object Height="Auto"/>  



大于或等于 0.0 Double 值的字符串表示形式。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.

如上所述的双精度值,后跟以下单元声明字符串之一: pxincm``ptA 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
元数据属性设置为 trueMetadata properties set to true AffectsMeasure