Skip to content

ComboBox Enum Description Annotation #8175

Answered by nielsbosma
silaros88 asked this question in Q&A
Discussion options

You must be logged in to vote

Maybe this can be some help:

public class EnumDescriptionConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value.GetType().IsEnum)
        {
            return ((Enum)value).ToDescription();
        }
        throw new ArgumentException("Convert:Value must be an enum.");
    }
    
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if(value is EnumDescription enumDescription)
        {
            return enumDescription.Value;
        }
        throw new ArgumentException("ConvertBack:EnumDescription must be an enum.");
    }
}

publi…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
1 reply
@silaros88
Comment options

Comment options

You must be logged in to vote
4 replies
@silaros88
Comment options

@nielsbosma
Comment options

@silaros88
Comment options

@silaros88
Comment options

Answer selected by maxkatz6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants