WPF EnumComboBox - Online Free Computer Tutorials.

'Software Development, Games Development, Mobile Development, iOS Development, Android Development, Window Phone Development. Dot Net, Window Services,WCF Services, Web Services, MVC, MySQL, SQL Server and Oracle Tutorials, Articles and their Resources

Thursday, June 28, 2012

WPF EnumComboBox

Selecting a value from an enumeration of appropriate values is a common task. A ComboBox is a well suited GUI element for that purpose. The ComboBox shows textual representations of all available values.

How do we get "nice" texts? A simple solution is the use of friendly names for the values, as does e.g.System.Drawing.Color[^] . But there is a drawback: a name must not contain white space (e.g. "Dark Blue" was changed to "DarkBlue").

A more advanced solution uses the Description attribute[^]. A converter, e.g. Description Enum TypeConverter[^], is used for the conversions from the value to the string and vice versa. Also a converter implementing WPF'sIValueConverter interface is available: Using DescriptionAttribute for enumerations bound to a ComboBox[^] .

When it comes to localization, things become more complicated. Most examples on the web only show how to get localized strings into the ComboBox, but omit the step from a user selection back to the enum value. Only Sacha Barber's great article Binding and Using Friendly Enums in WPF[^] shows how to do a two-way binding.


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too. 

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


No comments:

Post a Comment