I have two combobox where Parent has to show the list of Countries and the child combo has to show a list of cities of the choosen country.
The data is stored in a Diction
For the parent ComboBox, bind the SelectedItem to a property on your model:
Where SomePropertyOnModel is of the same type as an Item in the Countries List.
For the child ComboBox, everything should be the same:
Side Note: You'll notice that I specifically added the ItemsSource binding to both the ComboBoxes.
In the model, whenever the SomePropertyOnModel is set, update the CountriesCitiesList based on the value received, i.e.,:
private string _somePropertyOnModel;
public string SomePropertyOnModel
{
get { return _somePropertyOnModel; }
set
{
_somePropertyOnModel = value;
// call NotifyPropertyChanged
UpdateCountriesCitiesList();
}
}
private void UpdateCountriesCitiesList()
{
// set CountriesCitiesList based on the
// SomePropertyOnModel value
// CountriesCitiesList should be an ObservableCollection and the values
// should be cleared and then added.
CountriesCitiesList.Clear();
CountriesCitiesList.Add( "Springfield" );
}