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的更多信息,请访问和