Simple way of editing enumerators using ComboBox in WPF

Here is the simple way of setting ComboBox for editing values of some enum type.
I would not use in application for production, since it’s not localizable etc. But when I need to quicky write some testing application, it works perfect.

First, put this to your resource section:


<Window.Resources>
<ObjectDataProvider
MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="keyName">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="a:enumType" />
ObjectDataProvider.MethodParameters>
ObjectDataProvider>

Window.Resources>

Then, in your combobox use it like this:


<ComboBox ItemsSource="{Binding Source={StaticResource keyName}}" SelectedItem="{Binding propertyName}">

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>