xaml:
<StackPanel>
<CheckBox Name="chk" Click="chk_Click"/>
<CheckBox Name="chk2" Click="chk_Click"/>
<CheckBox Name="chk3" Click="chk_Click"/>
</StackPanel>
后台代码:
private void chk_Click(object sender, RoutedEventArgs e)
{
var checkBoxes = new[] { chk, chk2, chk3}
var current = (CheckBox)sender
foreach (var checkBox in checkBoxes)
{
if (checkBox != current)
{
checkBox.IsChecked = !current.IsChecked
}
}
}
当然, 你还可以看RadioButton能不能达到你的要求,因为RadioButton可以通过设置GroupName来实现分组的目的。
你需要修改一下DataGridTemplateColumn.CellTemplate 就可以了。<DataGrid AutoGenerateColumns="False" IsReadOnly="True" CanUserAddRows="False" HorizontalAlignment="Stretch" Name="dataGrid1" VerticalAlignment="Stretch" HorizontalContentAlignment="Center" >
<DataGrid.Columns>
<!--<DataGridCheckBoxColumn x:Name="dgIscheck" Binding="{Binding IsCheck}" Header="状态" HeaderStringFormat="true" />-->
<DataGridTemplateColumn Header="状态" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="cbStatus" IsChecked="{Binding IsCheck}" Tag="{Binding ID}" Click="cbStatus_Click" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="ID" Width="170" Binding="{Binding ID}" />
<DataGridTextColumn Header="姓名" Width="80" Binding="{Binding UserName}" />
<DataGridTextColumn Header="Email" Width="170" Binding="{Binding MailAddress}" />
</DataGrid.Columns>
</DataGrid>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)