我会创建一个对象来保存您的类别,其中包含该类别可能的每种类型。就像是...
public class Category
{
public ObservableCollection<string> Types { get; set; }
}
然后当您初始化每个类别时,您可以设置允许哪些类型...
public class MyClass
{
public ObservableCollection<Category> Categories { get; set; }
public MyClass()
{
InitializeComponent();
ObservableCollection MyTypes = new ObservableCollection();
MyTypes.Add("type1");
MyTypes.Add("type2");
MyTypes.Add("Type3");
Categories.Add(new Category() { Types = MyTypes });
//Probably a more elegant way to do this, but hard to say based on information given
this.DataContext = this;
}
}
最后,您可以将第一个组合框绑定到类别列表,将第二个组合框绑定到另一个组合框的所选项目的类型列表。
<ComboBox Name="cboCategory" ItemsSource = "{Binding Categories}" />
<ComboBox ItemsSource = "{Binding ElementName=cboCategory, Path=SelectedItem.Types}" />