Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在xaml中写入ParentListBox.SelectedIndex?_C#_Wpf_Xaml_Combobox - Fatal编程技术网

C# 如何在xaml中写入ParentListBox.SelectedIndex?

C# 如何在xaml中写入ParentListBox.SelectedIndex?,c#,wpf,xaml,combobox,C#,Wpf,Xaml,Combobox,我有一个列表框,其中有组合框作为列表项。每个ListItem中的组合框都是使用ListBox的ItemTemplate创建的 现在,假设我有5个列表项。i、 五个组合框 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

我有一个列表框,其中有组合框作为列表项。每个ListItem中的组合框都是使用ListBox的ItemTemplate创建的

现在,假设我有5个列表项。i、 五个组合框

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.
所以,我想我必须为不同的组合框使用不同的数据源

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....>
    <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>


现在,我的问题是我应该如何使用父列表框的insead。在上面的代码中选择dex,我应该用什么替换Non-0?

对于非零部分,不使用
数据触发器
。。。您只需在
样式中将其设置为
Setter
,使其成为默认值,然后
DataTrigger
仅在值为
0
时更改
数据源
属性。试试这个:

<ComboBox....>
    <ComboBox.Style>
        <Style>
            <Setter Property="DataSource" Value="{Binding 
                Path=ListCorrespondingToValue2}"/>
            <Style.Triggers>
                <DataTrigger Binding="ParentListBox.SelectedIndex" Value="0">
                    <Setter Property="DataSource" Value="{Binding 
                        Path=ListCorrespondingToValue1}"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    <ComboBox.Style>
</ComboBox>


我不知道你是否能从这里到达那里。为什么不将第一个框中的选定项绑定到ViewModel中的属性,并在选定项的属性的setter中使用适当的itemsource加载下一个框?这不是一个真正的技巧。。。它只是以
样式.Setter
设置了一个属性,但我很高兴它有帮助。