Xamarin Switchcell绑定IsEnabledPropery无法正常工作?

时间:2016-06-19 09:02:47

标签: xamarin binding xamarin.forms

我只是创建一个简单的例子,我想通过打开/关闭另一个switchcell(名为switch1)来启用/禁用Switchcell(名为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));
        }
    }
}

1 个答案:

答案 0 :(得分:0)

实际上这是来自Xamarin的错误,我认为尚未修复首先检查没有绑定是否正常工作

相关问题