【发布时间】:2018-01-07 23:14:49
【问题描述】:
在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 时,所有的复选框都应该被选中。
【问题讨论】:
-
假设您遵循 MVVM 模式(您说您正在使用绑定):创建一个命令并设置所有布尔值
= true。
标签: c# xaml windows-phone-8.1