我可以使 WPF DataGridRow 变得不可选择吗?
我的数据网格上有一个样式可以根据属性绑定禁用 DataGridRow。这使得该行不可选择,这就是我想要的。但是,我仍然可以使用至少 2 种其他方法来选择禁用的行。第一个是如果我在禁用行周围的两个启用行之间使用拖动动作。第二个是如果我单击数据网格左上角的“全选”按钮。有没有办法使特定行完全不可选择?
这就是我目前所拥有的:
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<DataTrigger Binding="{Binding DisableMe}" Value="True">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
I have a style on my datagrid to disable a DataGridRow based on a property binding. This makes the row unselectable, which is what I want. However, I am still able to select the disabled rows using at least 2 other ways. The first is if I use a dragging motion between two enabled rows that surround the disabled row. The second is if I click on the "select all" button on the top left of the datagrid. Is there a way to make specific rows completely unselectable?
This is what I currently have:
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<DataTrigger Binding="{Binding DisableMe}" Value="True">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 SelectionChanged 事件撤消选择怎么样?无论如何,我真的认为没有直接的方法。
您还可以更改行样式,以便即使已选择它,它也显示为未选择,并通过代码过滤掉选择...
What about using the SelectionChanged event to undo the selection? I really don't think there is a straightforward way to it, anyway.
You could also change the row style so it appears unselected even if it IS selected, and filter it out the selection through code...
我刚刚偶然发现这个线程有同样的问题,我想指出你可以简单地将启用设置为 false。
I just stumbled upon this thread with the same problem, and I want to point out that you can simply set enabled to false.
我认为这个问题没有任何适当的解决方案。但作为解决方法,您可以将 DataGrid 的“IsHitTestVisible”属性绑定到“IsEnabled”。
I don't think of any proper solution to this question. But as a workaround you can bind 'IsHitTestVisible' property of DataGrid to 'IsEnabled'.