简体   繁体   English

如何在Xamarin.forms C#中隐藏布局?

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

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. 我有一个带开关控制的Stacklayout,当开关值为真时我必须显示布局,如果值变为false,我必须隐藏布局。 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. 任何人都可以建议我如何在Xamarin.forms中做到这一点。 Advance thanks guys for those helped me to solve the problem. 感谢那些帮助我解决问题的人。

Switch.cs 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
    }
}

From our discussion I have gathered that you want to show/hide a layout by toggling a Switch , in XAML . 从我们的讨论中我已经收集到您希望通过在XAML切换Switch来显示/隐藏布局。

For this we will be using data-binding . 为此,我们将使用数据绑定

Set your StackLayout.IsVisible property to bind to the Switch.IsChecked , like this: 设置StackLayout.IsVisible属性以绑定到Switch.IsChecked ,如下所示:

<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设置为取消选中,如下所示:

<Switch android:checked="false" android:textOn="Yes" android:textOff="No" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM