Xaml Xamarin使用可观察集合词典进行设置绑定
我有一个Xaml Xamarin使用可观察集合词典进行设置绑定,xaml,xamarin,data-binding,xamarin.forms,Xaml,Xamarin,Data Binding,Xamarin.forms,我有一个列表视图,它绑定到可观察集合的字典,它工作得很好: var Key = "something"; myListView.SetBinding(ListView.ItemsSourceProperty, $"Items[{Key}]"); 现在我需要将标签绑定到同一个源,如果列表为空,但不知道格式,则使用转换器显示可见性 myNoResultsLabel .SetBinding(IsVisible??, $"Items[{Key}]"??, Converter=MyEmpt
列表视图
,它绑定到可观察集合的字典
,它工作得很好:
var Key = "something";
myListView.SetBinding(ListView.ItemsSourceProperty, $"Items[{Key}]");
现在我需要将标签
绑定到同一个源,如果列表为空,但不知道格式,则使用转换器
显示可见性
myNoResultsLabel
.SetBinding(IsVisible??, $"Items[{Key}]"??, Converter=MyEmptyListIsTrueConverter??);
谢谢它看起来像:
myNoResultsLabel.SetBinding(Label.IsVisibleProperty, "NameOfProperty", BindingMode.Default, new MyEmptyListIsTrueConverter());
转换器:
public class MyEmptyListIsTrueConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((cast)value == value.count > 0)
{
return true
}
else
{
return false;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
有关IValueConverter的更多信息,请访问和