C# SwitchCell如何在Xamarin窗体上以编程方式设置开/关

C# SwitchCell如何在Xamarin窗体上以编程方式设置开/关,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我正在创建一个简单的Xamarin表单应用程序。在我的XAML页面中,我有两个SwitchCell,我想根据我的数据库设置开关。我的意思是,我想从我的代码后面打开我的Facebook SwitchCell。但我不知道我该怎么做 第XAML页: <TableView Intent="Form" x:Name="SwiCell" RowHeight="50"> <TableRoot> <TableSection Title="Social Network">

我正在创建一个简单的Xamarin表单应用程序。在我的XAML页面中,我有两个SwitchCell,我想根据我的数据库设置开关。我的意思是,我想从我的代码后面打开我的Facebook SwitchCell。但我不知道我该怎么做

第XAML页:

<TableView Intent="Form" x:Name="SwiCell" RowHeight="50">
<TableRoot>
    <TableSection Title="Social Network">
        <SwitchCell  Text="Facebook"/>
        <SwitchCell Text="Twitter"/>
    </TableSection>      
</TableRoot>

为每个SwitchCell添加一个x:名称:

<TableView Intent="Form" x:Name="SwiCell" RowHeight="50">
<TableRoot>
    <TableSection Title="Social Network">
        <SwitchCell x:Name="FacebookSwitch" Text="Facebook"/>
        <SwitchCell x:Name="TwitterSwitch" Text="Twitter"/>
    </TableSection>      
</TableRoot>

然后在C#中,您可以引用单元格,并根据需要从数据库中设置On属性:

public partial class MySetup : ContentPage
{
    public MySetup()
    {
        InitializeComponent();

        FacebookSwitch.On = <if Facebook is on>;
        TwitterSwitch.On = <if Twitter is on>;
    }
}
public分部类MySetup:ContentPage
{
公共MySetup()
{
初始化组件();
FacebookSwitch.On=;
TwitterSwitch.On=;
}
}
public partial class MySetup : ContentPage
{
    public MySetup()
    {
        InitializeComponent();

        FacebookSwitch.On = <if Facebook is on>;
        TwitterSwitch.On = <if Twitter is on>;
    }
}