Hi , I'll try to explain in a simple way (for example departments and persons)
public class Person{
public int Id{get;set;}
public string Name {get;set;}
}
public class Department{
public int Id{get;set;}
public string Name{get;set;}
public ObservableCollection<person> Persons {get;set;}
}
public class MainVM:ViewModelBase
{
public Person SelectedPerson {get;set}
public Department SelectedDepartment {get;set;}
public ObservanleCollection<department> Departments {get;set;}
}</department></person>
your window:
<window ....="" datacontext="{Binding">
<stackpanel>
...
<datagrid x:name="dgDeps" itemssource="{Binding Departments}" xmlns:x="#unknown">
SelectedItem="{Binding SelectedDepartment, Mode=TwoWay}".... />
<datagrid x:name="dgPersons" itemssource="{Binding SelectedDeoartment.Persons}">
SelectedItem="{Binding SelectedPerson, Mode=TwoWay}"
</datagrid></datagrid></stackpanel></window>
whats going on behind the scene, when you populate Departmnets property in MainVM
dgDeps automatically binds to all values and display it,
after you clicked on some department row, dgPersons will refresh bindings according to seleted department.
Hope this will help )