在 WPF DataGrid 中禁用选择 [英] Disable selecting in WPF DataGrid
本文介绍了在 WPF DataGrid 中禁用选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 WPFTooklit 的 DataGrid
中禁用选择?我尝试修改适用于 ListView
的解决方案(来自 WPF ListView 关闭选择),但这不起作用:
How can I disable selecting in a WPFTooklit's DataGrid
?
I tried modifying the solution that works for ListView
(from WPF ListView turn off selection), but that doesn't work:
<tk:DataGrid>
<tk:DataGrid.ItemContainerStyle>
<Style TargetType="{x:Type tk:DataGridRow}">
<Setter Property="Focusable" Value="false"/>
</Style>
</tk:DataGrid.ItemContainerStyle>
<tk:DataGrid.CellStyle>
<Style TargetType="{x:Type tk:DataGridCell}">
<Setter Property="Focusable" Value="false"/>
</Style>
</tk:DataGrid.CellStyle>
</tk:DataGrid>
推荐答案
对此有一个技巧.您可以处理 DataGrid(例如 dgGrid)的 SelectionChanged 事件并在处理程序中写入:
There is a trick for this. You can handle SelectionChanged event of the DataGrid(say dgGrid) and in the handler write:
dgGrid.UnselectAll();
它将取消选择所有选定的行,结果将是未选择行".
It will unselect all selected row and result will be "No row selected".
这篇关于在 WPF DataGrid 中禁用选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文