FrameworkElement.Height FrameworkElement.Height FrameworkElement.Height FrameworkElement.Height Property

定义

获取或设置元素的建议高度。Gets or sets the suggested height of the element.

public:
 property double Height { double get(); void set(double value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))]
[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, 最后是, 如果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.

如果此元素是某个其他元素内的子元素, 则将此属性设置为值实际上只是一个建议值。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情况下, 通常情况下, 是其他内容的子元素, 甚至是在HeightWindow设置时。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.NaNIn 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"/>  

XAML 值XAML Values

doubledouble
Double

等于或大于 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.

qualifiedDoublequalifiedDouble
如上所述的双精度值, 后跟以下单元声明字符串之一px:、 incmptA 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

AutoAuto
启用自动调整行为。Enables autosizing behavior. 请参阅“备注”。See Remarks.

依赖项属性信息Dependency Property Information

标识符字段Identifier field HeightProperty
元数据属性设置为trueMetadata properties set to true AffectsMeasure

适用于

另请参阅