FrameworkElement.Width 屬性


取得或設定元素的寬度。Gets or sets the width of the element.

 property double Width { double get(); void set(double value); };
[System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)]
public double Width { get; set; }
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None, Readability=System.Windows.Readability.Unreadable)>]
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.



這是指定寬度資訊的三個屬性之一 FrameworkElementThis is one of three properties on FrameworkElement that specify width information. 另外兩個是 MinWidthMaxWidthThe other two are MinWidth and MaxWidth. 如果這些值之間發生衝突,則必須先接受實際寬度判斷的應用程式順序, MinWidth MaxWidth 最後,如果每一個都在界限內,則為最後一個 WidthIf 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 Attribute UsageXAML Attribute Usage

<object Width="double"/>  


<object Width ="qualifiedDouble"/>  


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

如上所述的 雙精度 值,後面接著下列其中一個單元宣告字串: 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 WidthProperty
中繼資料屬性設定為 trueMetadata properties set to true AffectsMeasure