如何在c#中單擊Select_All
按鈕時檢查列表框中的所有複選框。如何在c中單擊selectAll時檢查所有複選框
這裏是我的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>
在ListBox中的數據從數據庫填充,所以當用戶點擊全選所有的複選框都應該得到遏制。
假設你是遵循MVVM模式(你說你正在使用綁定):創建一個命令並設置所有布爾值'= TRUE'。 –