UIElement.Opacity 屬性


取得或設定套用至整個 UIElement (在 使用者介面 (UI)user interface (UI) 中呈現時) 的不透明度因數。Gets or sets the opacity factor applied to the entire UIElement when it is rendered in the 使用者介面 (UI)user interface (UI). 這是相依性屬性。This is a dependency property.

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


不透明度因素。The opacity factor. 預設不透明度為 1.0。Default opacity is 1.0. 值必須介於 0.0 到 1.0 之間。Expected values are between 0.0 and 1.0.



1.0 預設值是這個相依性屬性在 UIElement 類別上的初始中繼資料所提供的預設值。The 1.0 default value is the default provided by the initial metadata of this dependency property on the UIElement class. 其他衍生的類別可能會透過覆寫其類別的函式中的中繼資料,來變更這個預設值。Other derived classes may potentially change this default value by overriding the metadata from within their class constructor.

除非也看到元素,否則 Opacity 的值不會套用至實際的配置(IsVisible true)。The value of Opacity won't be applied to actual layout unless the element is also visible (IsVisible is true).

Opacity 會從專案樹狀結構上的父項目套用至子專案,但不會在個別子專案的屬性值中指出嵌套不透明度設定的可見效果。Opacity is applied from parent elements on down the element tree to child elements, but the visible effects of the nested opacity settings aren't indicated in the property value of individual child elements. 比方說,如果清單有50% (0.5)的不透明度,而且其中一個清單專案的不透明度設定為20% (0.2),則該清單專案的淨可見不透明度將會轉譯為10% (0.1),但在查詢時,清單專案 Opacity 屬性的屬性值仍會是0.2。For instance, if a list has a 50% (0.5) opacity and one of its list items has its own opacity set to 20% (0.2), the net visible opacity for that list item will be rendered as if it were 10% (0.1), but the property value of the list item Opacity property would still be 0.2 when queried.

即使已宣告或已評估的不透明度為0,專案仍會參與輸入事件和命令,而且可能具有可設定的目標。Even if the declared or evaluated opacity is 0, an element still participates in input events and commands, and is potentially focusable. 這個層面很有用,例如,您可以使用不透明度零的物件(例如圖形),以透明的元素遮罩基礎物件。This aspect can be useful, for instance you can use an opacity-zero object (such as a shape) for masking underlying objects with transparent elements. 不透明度-零物件可以處理基礎區域的所有輸入事件處理。The opacity-zero object can then handle all the input event processing for an underlying area. 不過,即使 Transparent,也應該將物件或圖形的 BackgroundFill 設定為值,否則不會啟用點擊測試,也不會收到任何事件。However, the Background or Fill of the object or shape should be set to a value, even if it is Transparent, otherwise hit testing is not enabled, and no events are received.

相依性屬性資訊Dependency Property Information

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