0

I'd like to create a visibility converter which displays content if an observablecollection is empty or null. As this converter will be used on many screens, each collection will hold a different type (T).

How do I get a reference to the ObservableCollection of unknown type. This is what I have so far:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      if (value == null) return Visibility.Visible;
      if (value is ObservableCollection<object>)
      {
        var col = value as ObservableCollection<object>;
        return col.Count > 0 ? Visibility.Hidden : Visibility.Visible;
      }
      return Binding.DoNothing;
    }
GoalMaker
  • 905
  • 3
  • 9
  • 22

1 Answers1

8

You don't have to. Just cast to ICollection and get its Count.

Anvaka
  • 15,658
  • 2
  • 47
  • 56