You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SAE-2.01/MCTG/Views/Converter/Drag&DropConvert.cs

30 lines
1.1 KiB

using System;
using System.Globalization;
namespace Views
{
public class EnumToValuesConverter<T> : IValueConverter where T : struct, System.Enum
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
IEnumerable<T> result = Enum.GetValues<T>();
if (parameter != null && parameter is string)
{
var names = (parameter as string).Split(" ");
var excludedValues = names.Select(n => Enum.TryParse(n, true, out T result) ? (true, result) : (false, default(T)))
.Where(tuple => tuple.Item1)
.Select(tuple => tuple.Item2)
.Distinct();
result = result.Except(excludedValues).ToArray<T>();
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}