I have an enum representing possible configurations. (the following is just an example...)
public enum ConfigurationType {
[Description("Minimal Configuration")]
Minimal = 0,
[Description("Standard Configuration")]
Standard,
[Description("Premium Configuration")]
Premium
}
Right now I am binding a property of type ConfigurationType in my class to a ComboBox using a value converter (found here) to display the Description. That works fine. What I would like to do however, is be able to disable the selection of specific enum members on the fly, the result being they would not show up in the ComboBox.
I have tried converting this enum to be a flags enum and then binding to a set of the flags, but didn't get very far. Any pointers on that or other suggestions?
Edit - flags example
When trying to use flags, I changed the enum to:
[Flags]
public enum ConfigurationType {
[Description("Minimal Configuration")]
Minimal = 1 << 0,
[Description("Standard Configuration")]
Standard = 1 << 1,
[Description("Premium Configuration")]
Premium = 1 << 2
}
public ConfigurationType AvailableConfigs = ConfigurationType.Standard | ConfigurationType.Premium;
It actually works for being able to assign bitwise-or'd list of these to a variable such as AvailableConfigs (as shown above), but then the value converter part was the hang-up. I wasn't sure how to implement a value converter to get the description of each flag present in AvailableConfigs, and be able to convert back to a variable (also of ConfigurationType) such as SelectedConfiguration. The setter of SelectedConfiguration would of course enforce only one flag at a time being present.