WPF binding comboboxes to parent- child model
- by PaulB
I've got a model with a few tiers in it - something along the lines of ...
Company Employees Phone numbers
So I've got a ListBox showing all the companys in the model. Each ListBoxItem then contains two comboboxes ... one for employees, one for phone numbers.
I can successfully get the employee combo to bind correctly and show the right people, but I'd like the phone combo to show the numbers for the selected employee.
I'm just setting the DataContext of the ListBox to the model above and using the following data template for each item
<DataTemplate x:Key="CompanyBody">
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Path=CompanyName}"></Label>
<ComboBox Name="EmployeesCombo" ItemsSource="{Binding Path=Company.Employees}"></ComboBox>
<!-- What goes here -->
<ComboBox DataContext="???" ItemsSource="??" ></ComboBox>
</StackPanel>
</DataTemplate>
I've tried (naively)
<ComboBox ItemsSource="{Binding Path=Company.Employees.PhoneNumbers}" ></ComboBox>
and
<ComboBox DataContext="EmployeesCombo.SelectedValue" ItemsSource="{Binding Path=PhoneNumbers}" ></ComboBox>
and all other manner of combinations ...