This is a typical Master / Detail scenario, and there is a typical and simple way to solve it.
I am. Instead of loading descriptions as string[] inside your GetGroups method, load the enitre Group object or if there are many properties, create a view model with only two necessary properties, something like this:
class GroupViewModel { public int GroupId {get; set;} public string Description {get; set;} }
II. In NewItemViewModel add a property for the second ComboBox, say
class NewItemViewModel { private ObservableCollection<SubgroupViewModel> _subgroups; public ObservableCollection<SubgroupViewModel> Subgroups { get { if (_subgroups == null) _subgroups = new ObservableCollection<SubgroupViewModel>(); return _subgroups; } set { _subgroups = value; NotifyPropertyChanged("Subgroups"); } } }
III. Now in your NewItemViewModel properties will become something like this:
class NewItemViewModel { public GroupViewModel SelectedGroup { set { var currentlySelected = value;
I hope you understand that this is the main plan of the method. I think you can improve it a bit by using some Important Selectors properties and using other methods to load data.
source share