在我看来,您正在这里寻找主/细节结构:
数据项:
public class MyCommandDefinition
{
public string DisplayName {get;set;}
public List<MyParameter> Parameters {get;set;}
public Parameter SelectedParameter {get;set;}
}
public class MyParameter
{
public string DisplayName {get;set;}
//Additional properties depending on your needs.
}
视图模型:
public class MyViewModel
{
public List<MyCommandDefinition> Commands {get;set;}
public MyCommandDefinition SelectedCommand {get;set;}
}
XAML:
<ListBox ItemsSource="{Binding Commands"}"
SelectedItem="{Binding SelectedCommand}"
DisplayMemberPath="DisplayName"/>
<ComboBox ItemsSource="{Binding SelectedCommand.Parameters}"
SelectedItem="{Binding SelectedCommand.SelectedParameter}"
DisplayMemberPath="DisplayName"/>
NotifyPropertyChanged()
如果您要以编程方式更改它们并期望它们反映在 UI 中,请不要忘记所有这些属性。