【发布时间】: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