如何使WPF DataGrid列互斥复选框
展开全部
你需要修改一下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>
<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>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询