C# 如何在DataGrid WPF中禁用列选择?

C# 如何在DataGrid WPF中禁用列选择?,c#,wpf,xaml,datagrid,C#,Wpf,Xaml,Datagrid,我的数据网格中有这个列 <DataGridTemplateColumn Header="Delete" IsReadOnly="True" > <DataGridTemplateColumn.CellStyle> <Style TargetType="DataGridCell"> <Setter Property="Background" Value="Transparent"/> <Setter

我的数据网格中有这个列

<DataGridTemplateColumn Header="Delete" IsReadOnly="True" >
    <DataGridTemplateColumn.CellStyle>
     <Style TargetType="DataGridCell">
       <Setter Property="Background" Value="Transparent"/>
       <Setter Property="BorderBrush" Value="Transparent"/> 
      </Style>
       <DataGridTemplateColumn.CellStyle>
        <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
        <CheckBox IsChecked="{Binding Delete, UpdateSourceTrigger=PropertyChanged, 
         Mode=TwoWay}" />
         </DataTemplate>
      </DataGridTemplateColumn.CellTemplate>
 </DataGridTemplateColumn>


我想禁用此列的选择,因为如果用户单击此列,其行上的其他单元格也会被选中。因此,我想禁用此列选择,但允许复选框保持启用状态。

对于数据网格,将其更改为

<DataGrid SelectionUnit="CellOrRowHeader">


这将允许您为数据网格选择单个单元格,并将其更改为

<DataGrid SelectionUnit="CellOrRowHeader">


这应该允许您选择单个单元格

它工作了,但我必须修改datagrid上的事件触发器,然后从集合中获取行的标题(如果是“Delete”)我不会设置所选项目。它起作用了,但我必须修改datagrid上的事件触发器,然后从集合中获取行的标题,如果它的“删除”,我不会设置所选项目。