52 lines
1.1 KiB
C#
52 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
|
|
namespace BeWo.Converter
|
|
{
|
|
public class CollectionCountToBoolConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
try
|
|
{
|
|
int count;
|
|
|
|
switch (value)
|
|
{
|
|
case int i:
|
|
count = i;
|
|
break;
|
|
case ICollection collection:
|
|
count = collection.Count;
|
|
break;
|
|
case IEnumerable enumerable:
|
|
count = enumerable.Cast<object>().Count();
|
|
break;
|
|
default:
|
|
return false;
|
|
}
|
|
|
|
if (parameter is string s && s == "reverse")
|
|
{
|
|
return !(count > 0);
|
|
}
|
|
|
|
return count > 0;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|