Funky WPF - Enumerations and the Combo Box

Posted on

Binding a combo box to an enumeration in WPF is more work than it should be, creating an object data provider etc etc:

    <ObjectDataProvider MethodName="GetValues"
        ObjectType="{x:Type sys:Enum}"
            <x:Type TypeName="Character" />

Followed by

<ComboBox SelectedItem="{Binding Character}"
Source={StaticResource CharacterValues}} "/>

What a pain! I have just added 'EnumerationComboBox' to my Apex library - so now you can do this:

<!-- The combo box, bound to an enumeration. -->
SelectedEnumeration="{Binding Character}" />

No need for an ObjectDataProvider, an items source or anything – and if you decorate enum’s with the ‘[Description]’ attribute, it’ll use the description in the combo.

There’s an article/download here for anyone who's interested: