我有一個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