This commit is contained in:
2020-03-26 21:40:54 +01:00
parent 9ebeb7ad4b
commit 59d93a0212
3 changed files with 4 additions and 5 deletions

View File

@ -28,10 +28,10 @@ namespace ModernWpfPlayground.PropertyPresenter2
{
if (!(value is Enum enumValue)) return string.Empty;
var descriptionAttribute = enumValue.GetType()
.GetField(enumValue.ToString()).GetCustomAttributes(false)
.GetField(enumValue.ToString())?.GetCustomAttributes(false)
.OfType<DescriptionAttribute>().FirstOrDefault();
return descriptionAttribute?.Description ?? value.ToString();
return descriptionAttribute?.Description ?? value.ToString() ?? string.Empty;
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)