WPF binding comboboxes to parent- child model
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="Hori开发者_如何学Gozontal">
<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 ...
<ComboBox ItemsSource="{Binding ElementName=EmployeesCombo, Path=SelectedItem.PhoneNumbers}" ></ComboBox>
精彩评论