我有一个ListBox组合框作为ListItems。每个ListItem中的组合框都是使用ListBox的ItemTemplate创建的。如何在xaml中编写ParentListBox.SelectedIndex?
现在,假设我有5个ListItems。即5个组合框。
For the 1st ListItem i.e. 1st ComboBox I would like to have all the Items from database as ItemsSource.
For the 2nd ListItem i.e. 1st ComboBox I would like to have all the Items from database as ItemsSource.
For the 3rd ListItem i.e. 1st ComboBox I would like to have only the selected Items from above Comboboxes as ItemsSource.
For the 4th ListItem i.e. 1st ComboBox I would like to have only the selected Items from above Comboboxes as ItemsSource.
For the 5th ListItem i.e. 1st ComboBox I would like to have only the selected Items from above Comboboxes as ItemsSource.
所以,我认为我必须为不同的ComboBox使用不同的DataSource。
而要做到这一点,我有以下起始码:
<ComboBox....>
<ComboBox.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="ParentListBox.SelectedIndex" Value="0">
<Setter Property="DataSource" Value="{Binding Path=ListCorrespondingToValue1}"/>
</DataTrigger>
<DataTrigger Binding="ParentListBox.SelectedIndex" Value="Non-0">
<Setter Property="DataSource" Value="{Binding Path=ListCorrespondingToValue2}"/>
</DataTrigger>
</Style.Triggers>
</Style>
<ComboBox.Style>
</ComboBox>
现在,我的问题是,我应该怎么用的ParentListBox.SelectedIndex
INSEAD在上面的代码,我应该代之以非0?
我不知道你是否可以从这里到达那里。为什么不把第一个盒子上的选定项目绑定到ViewModel中的一个属性,并在选定项目的属性设置器中使用适当的项目源加载下一个盒子? – safetyOtter