2
我有以下目的:Xamarin.Forms数据绑定在代码为开关单元
public class Notification : INotifyPropertyChanged
{
private bool _trafficNot;
public bool TrafficNot
{
get { return _trafficNot; }
set {
if (value.Equals(_trafficNot))
return;
_trafficNot = value;
OnPropertyChanged();
}
}
private bool _newsNot;
public bool NewsNot
{
get { return _newsNot; }
set
{
if (value.Equals(_newsNot))
return;
_newsNot = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged([CallerMemberName]String propertyName=null)
{
var handler=PropertyChanged;
if(handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
我从一个这样的对象的数据:根据什么被存储在 //设置通知对象数据库 通知通知=新通知 {
TrafficNot = uInfo.NotificationTraffic,
NewsNot = uInfo.NotificationNews
};
,我希望将数据绑定到这些switchells
TableView tableView = new TableView
{
BindingContext = notification,
Intent = TableIntent.Form,
Root = new TableRoot
{
new TableSection
{
new SwitchCell
{
Text = "News",
BindingContext = "NewsNot"
},
new SwitchCell
{
Text = "Traffic",
BindingContext = "TrafficNot"
},
new SwitchCell
}
}
};
我还需要做什么来绑定它?
干杯
啊,谢谢你纠正这个错字,史蒂芬。 – 2014-09-24 07:19:55
谢谢 - 它不让我在TableSection中命名SwitchCell,所以我认为它们不能被命名 - 但是由于你的回答,我努力在桌子外面宣布。 – user1667474 2014-09-24 08:46:59