Xamarin使用可观察集合字典形成SetBinding

时间:2018-09-11 00:55:27

标签: xaml xamarin data-binding xamarin.forms

我有一个 https://drive.google.com/uc?authuser=0&id=[your ID without brackets]&export=download 绑定到listview的{​​{1}}上,并且效果很好:

Dictionary

我现在需要将Observable Collections绑定到同一源,并且如果列表为空但不知道格式,请使用var Key = "something"; myListView.SetBinding(ListView.ItemsSourceProperty, $"Items[{Key}]"); 来显示可见性

Label

谢谢

1 个答案:

答案 0 :(得分:1)

它看起来像:

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的更多信息,位于documentationexample