小编Sha*_*ris的帖子

选择所有复选框 WPF

我想通过选择带有“以上全部”的复选框名称来选中所有复选框。复选框位于列表框中

<ListBox SelectionMode="Multiple" 
         BorderThickness="0" 
         ItemsSource="{Binding QuestionThreeSelection}" 
         SelectedItem="{Binding QuestionThreeSelection}" 
         Name="listBoxList" 
         SelectionChanged="listBoxList_SelectionChanged">
    <ListBox.InputBindings>
        <KeyBinding Command="ApplicationCommands.SelectAll"
                    Modifiers="Ctrl"
                    Key="A" />
    </ListBox.InputBindings>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <CheckBox Checked="CheckBox_Checked_1"   
                      Content="{Binding SourceName}" 
                      IsChecked="{Binding Path=IsSelected,  Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)

返回代码

private void CheckBox_Checked_1(object sender, RoutedEventArgs e)
{          
    var oo = listBoxList;
    CheckBox cb = (CheckBox)sender;
    //var w=e;

    IEnumerable<AddSource> listallityem = ((IEnumerable<AddSource>)listBoxList.Items.SourceCollection).Where(r => r.IsSelected == false);
    //IEnumerable<AddSource> listallityem1 = ((IEnumerable<AddSource>)listBoxList.Items.SourceCollection);

    AddSource vv = cb.DataContext as AddSource;
    if ((bool) cb.IsChecked)
    {

    }

    if (vv.SourceName== "All of the above")
    {
        r …
Run Code Online (Sandbox Code Playgroud)

c# wpf checkbox

5
推荐指数
1
解决办法
5434
查看次数

标签 统计

c# ×1

checkbox ×1

wpf ×1