public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
// Determines whether the target type is nullable
bool isNullable = targetType.Name == typeof(Nullable<>).Name;
Type enumerationType = isNullable ? targetType.GenericTypeArguments.FirstOrDefault() : targetType;
// Gets the parameter and check if it is null, if so then the default value for the target type is returned
string enumValueName = parameter as string;
if (enumValueName == null)
throw new ArgumentException("The parameter was not set.");
// Converts the parameter to its target value
if ((bool)value)
return Enum.Parse(enumerationType, enumValueName);
else
return DependencyProperty.UnsetValue;
}