是否可以将 Datagrid 上的 CommitEditCommand 绑定到视图模型中的 ICommand?

发布于 2024-10-07 11:54:40 字数 304 浏览 7 评论 0原文

我正在尝试做类似的事情;

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2024-10-14 11:54:40

我最初的预感是否定的...这是基于 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 the DataGrid 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 the DataGrid hitting Enter (InputBinding stored via the CommandManager) will by default execute the DataGrid.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 or CellEditEnding to cancel the command which would mean in theory you could cancel the command and at that point route to your desired behavior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文