WPF: How to bind enum values to ComboBox

You can easily bind the values of an enum directly to a ComboBox by making a simple markup extension.

public class EnumValuesExtension : MarkupExtension
{
    private readonly Type _type;
    
    public EnumValuesExtension(Type type)
    {
        _type = type;
    }
 
    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        return Enum.GetValues(_type);
    }
}

Then you just need to call it like this, passing the enum to the extension constructor:

<ComboBox ItemsSource="{my:EnumValues my:Status}" />

Note: when calling extensions in XAML you can omit the “Extension” part at the end.

Related articles