VisualElement.Opacity 属性

定义

获取或设置呈现元素时应用于元素的不透明度值。 这是一种可绑定属性。

public double Opacity { get; set; }
member this.Opacity : double with get, set

属性值

不透明度值。 默认不透明度为 1.0。 设置时,值将固定在 0 到 1 之间。

注解

除非 IsVisible 为 true,否则不透明度值不起作用。 不透明度沿元素层次结构继承。 如果父级的不透明度为 0.5,而子级的不透明度为 0.5,则子级将以有效的 0.25 不透明度呈现。 将不透明度设置为 0 具有输入元素的未定义行为。

以下示例将布局的不透明度设置为 0.5,其中一个子元素的不透明度设置为 0.5,使子元素不透明为 25%。

StackLayout stack = new StackLayout ();
Button button1 = new Button {Text="A Button"};
Button button2 = new Button {Text="Another Button"};

stack.Children.Add (button1);
stack.Children.Add (button2);

// The stack and everything in it will become 50% opaque
stack.Opacity = 0.5;

// button1 will become 25% opaque while the stack and button2 remane 50% opaque
button1.Opacity = 0.5;

适用于