我有Tabs列表,其中Tab是:
public class Tab
{
public int Id {get; set;}
public string Name {get; set}
public List<country> Country {get; set;}
}
现在,我想将它绑定到两个组合框: 第一个组合框是好的,但是第二个我想显示国家列表。
<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}"/>
当我知道Id时,如何在第二个组合框中设置ItemsSource。 另一种方法是创建varible,比如selectedList然后绑定到它?
修改
我正在创建新的对话框,我正在发送带有标签ID的模型,对话框上下文有标签列表。
答案 0 :(得分:4)
使用ComboBox
给您的第一个x:Name="FirstComboBox"
姓名,并更改第二个ItemsSource
ComboBox
的{{1}}。
只是一个提示:在xaml中绑定集合时,请使用to ItemsSource="{Binding ElementName=FirstComboBox, Path=SelectedItem.Country}"
而不是ObservableCollection<T>
。