DataGrid SelectionUnit=Cell 禁用对选定行的所有支持? [英] DataGrid SelectionUnit=Cell disables all support for a selected row?

查看:16
本文介绍了DataGrid SelectionUnit=Cell 禁用对选定行的所有支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.Net 4 WPF DataGrid C# MMVM

.Net 4 WPF DataGrid C# MMVM

当 DataGrid SelectionUnit 为全行时,wpf 数据绑定和 collectionview 负责通过视图的 currentitem 属性在视图模型中让我知道主动选择的项目是什么.这对于选择模式设置为全行的只读网格非常有用.

When the DataGrid SelectionUnit is full row, wpf databinding and the collectionview take care of letting me know in the viewmodel what is the actively selected item via the view's currentitem property. This works great for readonly grids with the selection mode set to the fullrow.

现在我有了一个可编辑的网格.所以我设置了 SelectionUnit=Cell 以便更容易地发现一个单元格在哪个单元格中.现在突然间网格不再有任何跟踪选择项的能力.设置为单元格模式时,我什至无法设置 SelectedItem.所以现在视图模型总是认为它在第一行.我可以在网格中处理 SelectedCellsChanged 以找出我在哪一行,我只是无法让视图模型知道,因为无法再设置网格的 SelectedItem!

Now I have an editable grid. So I set the SelectionUnit=Cell to make it easier to spot which cell one is in. Now all of a sudden the grid no longer has any ability to track the selection item. I can't even set SelectedItem when set to cell mode. So now the viewmodel always thinks it's on the first row. I can handle SelectedCellsChanged in the grid to figure out what row I'm on, I just have no way of letting the viewmodel know since the grid's SelectedItem can no longer be set!

我不明白为什么在单元格选择模式下网格仍然不能有 SelectedItem.

I don't understand why the grid can't still have a SelectedItem when in cell select mode.

在我的网格中硬编码以将 ItemSource 投射到我的 collectionview 以从 SelectedCellsChanged 事件中调用 MoveCurrentTo,是否还有其他 MVVM 真正的方法来保持视图的 CurrentItem 与网格同步?

Short of hardcoding into my grid to cast the ItemSource to my collectionview to call MoveCurrentTo from the SelectedCellsChanged event, is there any other MVVM true way to keep the view's CurrentItem in sync with the grid?

或者,当我有可编辑的网格时,我更改网格样式以移除或减少行高亮效果.

Either that, or I change the grid style to remove or reduce the row highlight effect when I have an editable grid.

推荐答案

我一直在寻找同样的问题,找到了一个简单的解决方案

I was searching for the same problems and found a simple solution

要访问将 SelectionUnit 设置为 Cell 的行,您必须执行以下操作:

To access to the row with SelectionUnit set to Cell you have to do:

DataGridXX.SelectedCells[0].item

仅当您一次只能选择一个单元格时才有效(不在扩展模式下).

It works only if you can select only one cell at time (not in Extended mode).

这篇关于DataGrid SelectionUnit=Cell 禁用对选定行的所有支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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