禁用在WPF DataGrid中选择 [英] Disable selecting in WPF DataGrid

查看:523
本文介绍了禁用在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的SelectionChanged事件(例如dgGrid),并在处理程序中写:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆