VisualElement.IsVisible VisualElement.IsVisible Property

Definition

Gets or sets a value that determines whether this elements should be part of the visual tree or not. This is a bindable property.

[Xamarin.Forms.TypeConverter(typeof(Xamarin.Forms.VisualElement/VisibilityConverter))]
public bool IsVisible { get; set; }
member this.IsVisible : bool with get, set
Property Value

true if the element should be rendered; otherwise, false. Default value is true.

Remarks

Setting IsVisible to false will remove the element from the visual tree. The element will no longer take up space in layouts or be eligle to receive any kind of input event.

The following example shows a stack where the middle element is toggled when a button is activated.


  partial class LabelToggle {
    Label label;

    void Build ()
    {
      var firstView = new Button {Text = "Tap Me"};
      label = new Label {Text = "I can be toggled"};
      var thirdView = new Image {Source = "image.png"};

      firstView.Activated += OnButtonActivated;

      Content = new StackLayout {
        Children {
          firstView,
          label,
          thirdView
        }
      };
    }

    void OnButtonActivated (object sender, EventArgs args)
    {
      label.IsVisible = !label.IsVisible;
    }
  }

Applies to