Xamarin.Forms Guides | Samples

Xamarin.Forms.VisualElement.IsVisible Property

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

Syntax

public Boolean IsVisible { get; set; }

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.

C# Example

  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;
    }
  }

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