Share via


VisualElement.Opacity Property

Definition

Gets or sets the opacity value applied to the element when it is rendered. This is a bindable property.

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

Property Value

System.Double

The opacity value. Default opacity is 1.0. Values will be clamped between 0 and 1 on set.

Remarks

The opacity value has no effect unless IsVisible is true. Opacity is inherited down the element hierarchy. If a parent has 0.5 opacity, and a child has 0.5 opacity, the child will render with an effective 0.25 opacity. Setting opacity to 0 has undefined behavior with input elements.

The following example sets the opacity of a layout to 0.5 and the opacity of one of its children to 0.5, making the child 25% opaque.

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;

Applies to