【问题标题】:Xamarin Forms SetBinding with Dictionary of Observable CollectionsXamarin Forms SetBinding 与可观察集合字典
【发布时间】:2018-09-11 00:55:27
【问题描述】:

我有一个listview 绑定到Observable CollectionsDictionary 并且效果很好:

var Key = "something"; 
myListView.SetBinding(ListView.ItemsSourceProperty, $"Items[{Key}]");

我现在需要将Label 绑定到同一个源,并使用Converter 在列表为空但不知道格式时显示可见性

myNoResultsLabel
      .SetBinding(IsVisible??, $"Items[{Key}]"??, Converter=MyEmptyListIsTrueConverter??);

谢谢

【问题讨论】:

    标签: xaml xamarin data-binding xamarin.forms


    【解决方案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();
        }
    }
    

    documentationexample 上有关 IValueConverter 的更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多