I am using this: Databinding an enum property to a ComboBox in WPF databinding for my comboboxes. I am unable to set the value of the comboboxes programatically though. Once it is bound, I can't set the SelectedItem, SelectedValue, or Text.
There must be a way to do this? Any help is appreciated.
To clarify, I have a comboBox bound to an enum that has all 50 states. I have a state value of the same type as the enum that the comboBox is bound to. I want to set the comboBox value to the value of my state.
If you bind the SelectedItem of the ComboBox to an underlying class, you should be able to change the binding by changing that class.
For example, let's say your enum was called "Country" and you had a class called "Person" and that person had a property called "CountryOfOrigin" and you want to bind it to a ComboBox. You could do this:
XAML file:
Code-behind: