简体   繁体   English

WPF DataGrid - 单击时将一列行为更改为不是 select 该行

[英]WPF DataGrid - change one column behavior to not select the row when clicked on

I have a DataGrid with 3 columns in total.我有一个共有 3 列的 DataGrid。 First two columns are my data and the last one is a delete column with only buttons in it.前两列是我的数据,最后一列是删除列,其中只有按钮。 When I click on any cell from the first two columns the target row gets selected and this is correct behaviour.当我单击前两列中的任何单元格时,目标行被选中,这是正确的行为。

The problem is I do not know how to disable this behaviour for the 3rd column and because of it when I want to delete an entry I do select it for a short time before it gets deleted.问题是我不知道如何为第 3 列禁用此行为,因此,当我想删除一个条目时,我会在它被删除之前短时间执行 select 它。

I do not want to write a workaround I want this column to not select its row when clicked.我不想写一个解决方法我希望这个列在单击时不是 select 它的行。 Is there any way to do it?有什么办法吗?

Below the code (I use Caliburn Micro so there is an action binding command):在代码下方(我使用 Caliburn Micro,所以有一个动作绑定命令):

<DataGrid>
  <DataGrid.Columns>
    <DataGridTextColumn/>
    <DataGridTextColumn/>
    <DataGridTemplateColumn CanUserReorder="False" CanUserSort="False" IsReadOnly="True">
      <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
          <Button Content="Delete"
                  cal:Message.Attach="[Event Click] = [Action Entries_DeleteEntry($dataContext)]"/>
        </DataTemplate>
      </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
  </DataGrid.Columns>
</DataGrid>

Kind Regards!亲切的问候!

You can do this by setting the "SelectionUnit" property to "Cell."您可以通过将“SelectionUnit”属性设置为“Cell”来做到这一点。 In that mode, cells can be selected individually, and the "SelectedItem" property always returns null.在该模式下,可以单独选择单元格,并且“SelectedItem”属性始终返回 null。 See the link below for more information:有关更多信息,请参阅下面的链接:
http://dotnetpattern.com/wpf-datagrid-selectionmode http://dotnetpattern.com/wpf-datagrid-selectionmode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM