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 设置的可见效果不会在各个子元素的属性值中指定。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. 但是,对象或形状的 BackgroundFill 应设置为一个值,即使它是 Transparent,也不会启用命中测试,也不会接收任何事件。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
元数据属性设置为 trueMetadata properties set to true NoneNone