How to hide out a layout in Xamarin.forms C#?

10,385

From our discussion I have gathered that you want to show/hide a layout by toggling a Switch, in XAML.

For this we will be using data-binding.

Set your StackLayout.IsVisible property to bind to the Switch.IsChecked, like this:

<StackLayout x:Name="employee" IsVisible="{Binding NameOfSwitch.IsChecked}">...</StackLayout>

Also you noted that the layout has to be hidden by default. To implement this we will set the Switch to be unchecked by default like this:

<Switch android:checked="false" android:textOn="Yes" android:textOff="No" />
Share:
10,385
Manoj
Author by

Manoj

Updated on June 14, 2022

Comments

  • Manoj
    Manoj almost 2 years

    I have a Stacklayout with switch control, when the switch values are true i have to show the layout and if the value changes to false i have to hide the layout. Based on some samples, i saw how to hide out a button but for hiding out a layout i can't find one. Can anyone suggest me how to do it in Xamarin.forms. Advance thanks guys for those helped me to solve the problem.

    Switch.cs

    void switchControl(object sender, ToggledEventArgs e)
    {
        if (e.Value == false)
        {
            StackLayout view = this.FindByName<StackLayout>("employee");
            //hide the layout gone or invisible          
        }else{
            //show the layout visible
        }
    }