by Dean
A contractor colleague of mine (Phil Steel) had an interesting Silverlight problem yesterday. He wanted to populate a Silverlight ComboBox with an enumeration, and implement 2-way binding to a property on his Data class (i.e. binding his property to the ‘SelectedItem’ on the ComboBox.
His requirements were as follows:
- The solution must have full design-time support in Expression Blend
- The code must give the developer an opportunity to create metadata for the enumeration that can be used for ‘user friendly’ visual values in the ComboBox
- There must be full 2-way binding, so no need to tap into the ‘SelectionChanged’ event to update the data object.
- Minimal C# code, with as much as possible being re-useable ‘as is’ for any enumeration.
Ok, so I googled around and only found fragments of a possible solution, so I decided to engineer one myself.