I\'m trying to do an \"empty list to visibility converter\" for WPF. This is an IValueConverter that takes an object ( that should be a list ) and if the list is empty (or i
I think its quite straight forward, here you go:
public class NullOrEmptyCollectionToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return Visibility.Collapsed;
var collection = value as ICollection;
return collection != null ? (collection.Count == 0 ? Visibility.Collapsed : Visibility.Visible) : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Hoping wil help, thanks! - Shams