Combobox binding

Feb 12, 2011 at 2:21 PM

What is the best practice for combobox binding conventions?

Suppose I have a combobox for selecting a country. Country is a class with properties CountryCode (eg. UK, BE, FR, US) and CountryDescription. My viewmodel has properties Countries (collection of Country objects) and a string property CountryCode.
Binding a combobox to Countries is easy, just give the combox x:Name="Countries" sets up the binding. 

But, how do I define the ComboBox so that when 

1. the screen is displayed, the combobox shows the matching item for CountryCode, if CountryCode contains a value?

2. CountryCode gets set when I select a country in the combobox?

3. What if this was a viewmodel for Person and CountryCode is a property of Person, like this:

  PersonViewModel {
public Person { ... }
        public ObservableCollection<Countries> Countries
  }

Person {
pulbic CountryCode { .. }

}

Feb 15, 2011 at 4:40 AM

+1 for an answer on this one please.

Coordinator
Feb 15, 2011 at 1:41 PM

There's no convention for this scenario. If you can think of a reasonable convention that would work, I may be able to add it. I can't think of anything though. In these scenarios, I normally just revert to explicit databinding.