【问题标题】:Xamarin Switchcell binding IsEnabledPropery not working?Xamarin Switchcell 绑定 IsEnabledPropery 不起作用?
【发布时间】:2016-06-19 09:02:46
【问题描述】:

我只是创建一个简单的示例,我想通过打开/关闭另一个开关单元(名为 switch1)来启用/禁用一个开关单元(名为 switch2)。 我正在使用绑定方法。我已经用“Entry”元素(试图禁用它)尝试了这段代码,它运行良好,但使用“switchcell”的属性“IsEnabledProperty”似乎不起作用。 (我没有使用 Xaml,我使用的是 PCL)。 Xamarin Forms 更新到最新版本 (2.3.0.49)。 这是 Xamarin 问题吗? 代码如下:

 BindingContext = new DetailsViewModel();

        SwitchCell switch1 = new SwitchCell()
        {
            Text = "Switch",
        };
        switch1.SetBinding(SwitchCell.OnProperty, new Binding("Test", BindingMode.TwoWay));

        SwitchCell switch2 = new SwitchCell()
        {
            Text = "Visibilita",
        };
        switch2.SetBinding(SwitchCell.IsEnabledProperty, "Test");

这里是 DetailsViewModel.cs:

 public class DetailsViewModel : INotifyPropertyChanged
 {
    bool test;


    public bool Test 
    { 
        get { return test; }
        set
        {
            if (test != value)
            {
                test = value;
                OnPropertyChanged("Test");
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged(string propertyName)
    {
        var changed = PropertyChanged;
        if (changed != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

【问题讨论】:

    标签: xamarin binding xamarin.forms


    【解决方案1】:

    实际上这是 Xamarin 的错误,我认为尚未修复首先检查不绑定是否有效

    【讨论】:

    • 谢谢,我试过不绑定,还是不行。有解决办法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2017-08-18
    • 2021-07-21
    • 1970-01-01
    相关资源
    最近更新 更多