是否可以将 Datagrid 上的 CommitEditCommand 绑定到视图模型中的 ICommand?
我正在尝试做类似的事情;
<Button Command="{Binding DeleteCommand}" />
其中DeleteCommand是视图模型公开的ICommand。
我以为我可以做类似以下的事情,但事实似乎并非如此;
<DataGrid CommitEditCommand="{Binding CommitCommand}" />
基本上我试图捕获视图模型中发生的事件并对其采取行动。我在这里缺少什么?
I'm trying to do something similar to;
<Button Command="{Binding DeleteCommand}" />
Where DeleteCommand is an ICommand exposed by the view model.
I thought i could do something similar to the following, but this doesn't seem to be the case;
<DataGrid CommitEditCommand="{Binding CommitCommand}" />
Basically i'm trying to capture the event occurence in the view model and act on it. What am I missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最初的预感是否定的...这是基于 Vincent Sibal 的 博客。
看来
DataGrid
上的CommitEditCommand
调用 IEditableCollectionView 对应项。所以...DataGrid.CommitEditCommand
->IEditableCollectionView.CommitEdit
->IEditableObject.EndEdit
因此,如果您的模型正在实现
IEditableObject
并且您位于DataGrid
内的单元格上,按 Enter 键(通过 CommandManager 存储的 InputBinding)将会默认情况下执行DataGrid.CommitEditCommand
并启动下游的级联操作,如上面提到的。该博客确实谈到了使用
RowEditEnding
或等事件>CellEditEnding
取消命令,这意味着理论上您可以取消命令,然后路由到您想要的行为。My initial hunch is no...this is based off the readings from Vincent Sibal's blog.
It appears that the
CommitEditCommand
on theDataGrid
calls the IEditableCollectionView counterpart. So...DataGrid.CommitEditCommand
->IEditableCollectionView.CommitEdit
->IEditableObject.EndEdit
Therefore if your model is implementing
IEditableObject
and you were on a cell within theDataGrid
hitting Enter (InputBinding stored via the CommandManager) will by default execute theDataGrid.CommitEditCommand
and set off the cascade of actions down stream as mentione dabove..The blog does speak about making use of events such as
RowEditEnding
orCellEditEnding
to cancel the command which would mean in theory you could cancel the command and at that point route to your desired behavior.