WPF binding comboboxes to parent- child model
Posted
by PaulB
on Stack Overflow
See other posts from Stack Overflow
or by PaulB
Published on 2010-05-21T12:27:40Z
Indexed on
2010/05/21
12:30 UTC
Read the original article
Hit count: 191
wpf
|databinding
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 ...
© Stack Overflow or respective owner