C# 如何在c中单击selectAll时选中所有复选框#

C# 如何在c中单击selectAll时选中所有复选框#,c#,xaml,windows-phone-8.1,C#,Xaml,Windows Phone 8.1,如何在c#中单击Select_all按钮时选中列表框中的所有复选框 这是我的XAML: <StackPanel Width="400" Orientation="Horizontal" Grid.Row="0"> <AppBarButton x:Name="Btn_SelectAll" Margin="20,0,0,0" Label="Select All" Icon="SelectAll" Click="Btn_SelectAll_Click" FontWeight=

如何在c#中单击
Select_all
按钮时选中列表框中的所有复选框

这是我的
XAML

<StackPanel Width="400" Orientation="Horizontal" Grid.Row="0">
    <AppBarButton x:Name="Btn_SelectAll" Margin="20,0,0,0" Label="Select All" Icon="SelectAll" Click="Btn_SelectAll_Click" FontWeight="Bold" />
    <AppBarButton x:Name="Btn_Delete" Margin="150,0,0,0" Label="Delete All" Icon="Delete" Click="DeleteAll_Click" FontWeight="Bold" />
</StackPanel>
<ListBox  x:Name="listBoxobj" Background="Transparent" Margin="6" Height="auto" BorderThickness="2" MaxHeight="580" Grid.Row="1" SelectionChanged="listBoxobj_SelectionChanged">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <CheckBox Name="Option1CheckBox"  VerticalAlignment="Center" Margin="5,0,0,0" />
            <TextBlock x:Name="NameTxt" TextWrapping="Wrap" Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="22" Foreground="White"/>
            <TextBlock x:Name="Age"   TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="White" FontSize="22" Text="{Binding Age}" />
        </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>


列表框中的数据是从数据库填充的,因此当用户单击SelectAll时,所有复选框都应该被选中。

在代码隐藏中创建一个公共/受保护字段

protected bool SelectAll = false;
Btn\u SelectAll\u单击
eventhandler,设置
SelectAll=true

使用SelectAll字段绑定
选项1复选框
已选中
属性,如下所示:

<CheckBox Name="Option1CheckBox"  VerticalAlignment="Center" Margin="5,0,0,0" IsChecked="{Binding SelectAll}" />

在CodeBehind中创建一个公共/受保护字段

protected bool SelectAll = false;
Btn\u SelectAll\u单击
eventhandler,设置
SelectAll=true

使用SelectAll字段绑定
选项1复选框
已选中
属性,如下所示:

<CheckBox Name="Option1CheckBox"  VerticalAlignment="Center" Margin="5,0,0,0" IsChecked="{Binding SelectAll}" />


假设您遵循MVVM模式(您说您正在使用绑定):创建命令并设置所有bool值
=true
。假设您遵循MVVM模式(您说您正在使用绑定):创建命令并设置所有bool值
=true
。这不起作用:(.我想数据没有被绑定。SelectAll应该是一个get/set字段:protected bool SelectAll{get;set}=false;这不起作用:(.我想数据没有被绑定。SelectAll应该是一个get/set字段:protected bool SelectAll{get;set}=false;