Binding Flagged Enumerations

added by thejet
10/13/2011 9:11:33 AM

196 Views

Flagged enumerations can present a difficult problem for data binding, this article presents a solution for binding these enumerations to individual CheckBox(s) in a WPF sample application.


4 comments

dpeterson
10/13/2011 9:13:08 AM
Very clever solution! I agree that leveraging the viewmodel is a much cleaner approach.
Do you think you could expand a little more on what's going on with your FlaggedEnumViewModel class?

thejet
10/17/2011 9:59:51 AM
I'd be happy to, do you have any specific questions? Really the brunt of what's going on is the translation of the convention-based property name into the associated flag, then checking against the underlying data to return the correct boolean, or set/clear the appropriate bit on the underlying value.

bradygaster
10/13/2011 2:55:48 PM
Excellent code. This is one of those "it-seems-like-it'd-be-easy" things that is explained really well. I'd like to see the author do some deeper discussion and maybe describe how to do dynamic binding in WPF.

thejet
10/17/2011 10:02:12 AM
Thanks! I do plan to do additional posts in the future, but time [and interesting topics] are hard to come by :)