C# 创建包含选中复选框值的组合框

C# 创建包含选中复选框值的组合框,c#,wpf,xaml,mvvm,combobox,C#,Wpf,Xaml,Mvvm,Combobox,我正在创建一个复选框列表和一个组合框,其中包含WPF MVVM应用程序中的复选框列表。我不知道如何从复选框中绑定combobox选中值的文本 以下是我尝试过的: <ComboBox ItemsSource="{Binding Systems}" Grid.Row="4" Grid.Column="1" IsEditable="True" IsReadOnly="True" Text="{}"> <ComboBox.ItemTemplate>

我正在创建一个
复选框列表和一个
组合框,其中包含WPF MVVM应用程序中的复选框列表。我不知道如何从复选框中绑定combobox选中值的文本

以下是我尝试过的:

<ComboBox ItemsSource="{Binding Systems}" Grid.Row="4" Grid.Column="1" 
    IsEditable="True" IsReadOnly="True" Text="{}">
     <ComboBox.ItemTemplate>
       <DataTemplate>
        <CheckBox Content="{Binding TemplateName}" IsChecked="{Binding 
          IsSystemChecked, UpdateSourceTrigger=PropertyChanged}"/>
       </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

这应该可以做到:

<StackPanel>
    <ListView ItemsSource="{Binding Systems}" >
        <ListView.ItemTemplate>
            <DataTemplate>
                <CheckBox Content="{Binding TemplateName}" IsChecked="{Binding 
                    IsSystemChecked, UpdateSourceTrigger=PropertyChanged}"/>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

    <ComboBox ItemsSource="{Binding Systems}" DisplayMemberPath="TemplateName" >
        <ComboBox.Style>
            <Style TargetType="ComboBox">
                <Setter Property="ItemContainerStyle">
                    <Setter.Value>
                        <Style TargetType="ComboBoxItem" BasedOn="{StaticResource {x:Type ComboBoxItem}}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsSystemChecked}" Value="False">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Setter.Value>
                </Setter>
            </Style>
        </ComboBox.Style>
    </ComboBox>
</StackPanel>

这里有:

  • ListView
    包含
    Systems
    中每个项目的复选框,该复选框绑定到
    IsSystemChecked
    属性
  • 组合框
    包含
    系统中的所有项目
    但是,如果
    IsSystemChecked
    属性为false,则
    可见性
    设置为
    折叠
    ,因此不会显示

如果您有任何问题,请告诉我!希望这能有所帮助。

请您重新表述一下您想做的事情好吗?我的问题是,用户何时会选中复选框项目在combobox中的显示方式,所以您想要一个复选框列表和包含复选框列表的combobox?是的,我想要的正是这个