【发布时间】:2016-07-19 11:02:07
【问题描述】:
我必须将字符串集合绑定到包含具有这些字符串的元素的列表视图,但我不知道该怎么做:
name.SetBinding(Label.TextProperty, ??? );
我知道在 xaml 中我可以做到这一点
<Label Text="{Binding }"/>
但是代码隐藏中的等价物是什么? 我需要 customcell,因为 listitem 还有其他元素
视图模型:
private BindableCollection<string> _wifiNetworks;
public BindableCollection<string> WifiNetworks
{
get { return _wifiNetworks; }
set
{
if (value != _wifiNetworks)
{
_wifiNetworks = value;
NotifyOfPropertyChange(() => WifiNetworks);
}
}
}
在视图中:
var wifiList = new ListView
{
RowHeight = 50
};
wifiList.SetBinding(ListView.ItemsSourceProperty, new Binding("WifiNetworks"));
wifiList.ItemTemplate = new DataTemplate(typeof(CustomCell));
CustomCell.cs:
public CustomCell()
{
var name = new Label
{
TextColor= (Color)Application.Current.Resources["ForegroundColor"],
FontSize = 17
};
name.SetBinding(Label.TextProperty, ??? );
}
【问题讨论】:
-
String没有实现INotifyPropertyChanged。适合你吗?
标签: c# xamarin xamarin.forms