Binding And Using Localized Enums In WPF

The other day I had to use some enums in WPF, where I wanted them to appear in a ComboBox to allow the user to select one of them.

Imagine that I had enum values like PizzaWithPepperoni, BaconDoubleCheeseBurger etc etc. I managed to get this bound in WPF fairly easily, but I wanted a way of showing some friendly values whilst still maintaining the correct value behind the scenes when a new selection was made.

So I set about doing this, and came up with a solution that used the EnumMemberAttribute, and then submitted this article to codeproject.

The original article was up for about 2 minutes and Josh Smith, said "ah what about Localization". Damn….luckily another codeproject great, Uwe Keim, posted some code to fix this. I also got a fabulous email from Infragistics great, Andrew Smith, who outlined an alternative approach, which makes use of a MarkupExtension.

I will not post any code/further explanation here as its all talked about in quite a bit of detail within the article.

Here are the relevant links

My article

http://www.codeproject.com/KB/WPF/FriendlyEnums.aspx

Andrews Smith alternative approach, which  is also a good (great) read

http://agsmith.wordpress.com/2008/09/19/accessing-enum-members-in-xaml/

Advertisements

3 thoughts on “Binding And Using Localized Enums In WPF

  1. […] Binding and Using Localized Enums in WPF (Sacha Barber) […]

  2. Uwe says:

    Wow, cool, thanks for mentioning me!

  3. sacha says:

    No worries man

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: