在 WPF DataGrid Row 中禁用焦点
我有一个 C# WPF DataGrid。在管理员模式下,用户可以在 DataGrid 中高亮显示并选择行,然后使用 PreviewKeyDown
按下“D”来删除它们。在操作员模式下,此功能将被禁用,用户只能滚动和阅读卷,但无法突出显示或选择要删除的行。
我可以将行高亮显示并删除。但我不知道如何禁用此功能。 我尝试过:
IsReadOnly = false
呈现 DataGrid 不可滚动Focusable = false
用户仍然可以高线显示并选择仍然可见的行IsHitTestVisible = false
。
如何?
I have a C# WPF DataGrid. In administrator mode, user can highline and select rows in DataGrid and key down a "D" to remove them using PreviewKeyDown
. In operator mode, this feature will be disabled and user can only scroll and read rolls but cannot highline or select rows to delete.
I can get the rows to be highlined and removed. But I don't know how to disable this feature.
I tried:
IsReadOnly = false
renders the DataGrid not scrollableFocusable = false
user can still highline and select the rowsIsHitTestVisible = false
still visible..
How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在
DataGridRow
上设置IsEnabled="False"
来禁用DataGrid
中的选择,同时仍保持排序、滚动等。这会带来副作用,即大多数元素都会呈现“灰色”/禁用外观,但
TextBlocks
却并非如此。You could disable selection in the
DataGrid
while still keeping sorting, scrolling etc. by settingIsEnabled="False"
onDataGridRow
.This has the sideeffect that most elements get the "grayed-out"/disabled look, however this is not the case for
TextBlocks
.