Reputation: 257
I have list of Tabs where Tab is:
public class Tab
{
public int Id {get; set;}
public string Name {get; set}
public List<country> Country {get; set;}
}
Now, I want to bind it to two comboboxes: First combobox is ok, but at second I want to display country list.
<custom:ComboBox Title="Tab"
ItemsSource="{Binding Tabs, Mode=TwoWay}"
ValuePath="Id"
Value="{Binding Model.Id, Mode=TwoWay}"
DisplayPath="Name"
IsEnabled="{Binding IsEnabled, Mode=TwoWay}"/>
<custom:ComboBox Title="Country"
SelectedItem="{Binding Model.Country, Mode=TwoWay}"
ItemsSource="{}"
DisplayPath="CountryName"
IsEnabled="{Binding IsEnabled, Mode=TwoWay}"/>
How to set ItemsSource at second combobox when I know Id. Is another way than create varible, like selectedList and then bind to it?
EDIT
I am creating new dialogbox and I'm sending model with tab id and dialogbox context have tab list.
Upvotes: 3
Views: 1072
Reputation: 6155
Give your first ComboBox
a name with x:Name="FirstComboBox"
and change your ItemsSource
of the second ComboBox
to ItemsSource="{Binding ElementName=FirstComboBox, Path=SelectedItem.Country}"
.
Just a hint: When binding collections in xaml use ObservableCollection<T>
instead of List<T>
.
Upvotes: 4