The easiest way to do this is to create a property to bind to the second ComboBox.ItemsSource
property. Now I've done this with classes many times, but not enum
s, so it might not work, but it should. Normally, my classes would have to derive from one base class, so that the property could be of that type. In your case, you could try this:
public ObservableCollection<Enum> Collection2 { get; set; } // Implement INPC interface
...
<ComboBox x:Name="cbox2" ItemsSource="{Binding Collection2}" ... />
Now lets assume that you have other collections that contain all of the values of your enum
s:
private List<BmwColours> bmwColours; // Fill these collections with correct values
private List<ToyotaColours> toyotaColours;
private List<FordColours> fordColours;
When the user makes a selection from the first ComboBox
, you can fill the Collection2
property with the correct enum
values something like this:
Collection2 = new ObservableCollection<Enum>();
if (cbox1.SelectedItem == ModeOfTransportationEnum.BmwX5)
foreach (Enum enumInstance in bmwColours) Collection2.Add(enumInstance);
else if (cbox1.SelectedItem == ModeOfTransportationEnum.ToyotaCamry)
foreach (Enum enumInstance in toyotaColours) Collection2.Add(enumInstance);
...
Now Collection2
is full of the correct enum
values. You might need to tweak this a bit to suit your needs, but it should do the trick.