FrameworkElement.Width FrameworkElement.Width FrameworkElement.Width FrameworkElement.Width Property

定义

获取或设置元素的宽度。Gets or sets the width of the element.

public:
 property double Width { 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 Width { get; set; }
member this.Width : double with get, set
Public Property Width As Double

属性值

元素的宽度(以 与设备无关的单位(每个单位 1/96 英寸)device-independent units (1/96th inch per unit) 为单位)。The width 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. 请参阅“备注”以了解上限信息。See Remarks for upper bound information.

注解

这是指定宽度信息的三FrameworkElement个属性之一。This is one of three properties on FrameworkElement that specify width information. 另外两个是MinWidthMaxWidthThe other two are MinWidth and MaxWidth. 如果这两个值之间存在冲突, 则首先MinWidth必须执行实际的宽度确定的应用程序顺序, 然后MaxWidth, 如果Width其中每个的值都在边界内, 则为。If there is a conflict between these values, the order of application for actual width determination is first MinWidth must be honored, then MaxWidth, and finally if each of these are within bounds, Width.

此属性的返回值始终与任何设置为它的值相同。The return value of this property is always the same as any value that was set to it. 相反, 的ActualWidth值可能会有所不同。In contrast, the value of the ActualWidth may vary. 出于某种原因, 布局可能已拒绝建议的大小。The layout may have rejected the suggested size for some reason. 此外, 布局系统本身的工作方式相对于属性系统集, 可能Width尚未处理过特定大小调整属性更改的情况。Also, the layout system itself works asynchronously relative to the property system set of Width and may not have processed that particular sizing property change yet.

除了可接受Double的值, 此属性还可以为Double.NaNIn addition to acceptable Double values, this property can also be Double.NaN. 这是指定自动调整大小行为的方式。This is how you specify auto sizing behavior. 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 width available to it. 但请注意, 特定控件经常以默认样式提供默认值, 这些默认值将禁用自动调整大小行为, 除非专门重新启用。Note however that specific controls frequently supply default values in their default styles that will disable the auto sizing behavior unless it is specifically re-enabled.

除了验证检查外, 还会为布局系统强制实施非确定性上限Width值 (这是一个非常大的数字, Single.MaxValue大于但Double.MaxValue小于)。In addition to the validation check, there is a nondeterministic upper value bound for Width 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. 不要将值Width设置为大于任何可能的视觉显示大小的最大大小的值, 否则可能会超出此不确定性的上限。Do not set Width 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 Width="double"/>  

- 或 --or-

<object Width ="qualifiedDouble"/>  

-or-

<object Width ="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

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

依赖项属性信息Dependency Property Information

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

适用于