Xamarin.Forms Guides | Samples

Xamarin.Forms.VisualElement.Opacity Property

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

Syntax

public Double Opacity { get; set; }

Value

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.

C# Example

  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;

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0