从viewModel调用DataGrid.CancelEdit()? [英] call DataGrid.CancelEdit() from a viewModel?

查看:139
本文介绍了从viewModel调用DataGrid.CancelEdit()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在使用MVVM处理Silverlight应用程序。

我正在尝试创建一个取消按钮在我看来,取消在数据网格中所做的所有更改("BudgetDataGrid")。

由于我正在使用MVVM,我不能在我的视图中编写cancel方法:

I'm working on a silverlight app, using the MVVM.
I'm trying to create a cancel-button in my view that cancel all changes made in a datagrid ("BudgetDataGrid").
Since I'm working with MVVM I can't just write the cancel method in my view:

BudgetDataGrid.CancelEdit()

BudgetDataGrid.CancelEdit()

是否有某种方式来"触发"来自我的viewmodel的这个方法?

Is it some way to "trigger" this method from my viewmodel?

Marius  H Enerud

Marius H Enerud

推荐答案

您好

根据您的解释,我的理解是您的取消按钮位于datagrid。

As per your explantion what i understand is that your Cancel button is outside the datagrid.

如果您的取消按钮位于Datagrid之外,那么您只需在ViewModel中创建命令并将其与您的按钮Command Property绑定。

If your cancel button is outside the Datagrid then you can simply create command  in ViewModel and bind it with your button Command Property.

使用命令会附加方法,您可以在其中编写取消逻辑,或者您可以刷新数据网格绑定的集合。

With command there will be method attached in which you can write cancel logic or you can siply refresh the collection with which your datgrid is binded.

例如

In View <Button Command="{Binding CancelEditCommand}"/>

希望这可以帮助你,万一你不是exa告诉我,我可以更正你的代码。

如果你需要如何实施指挥你可以参考下面的链接 

if you need how to implement commanding u can refer below link 

http://www.codeproject.com/Articles/238657/How-to-use-Commands-in-WPF

http://www.codeproject.com/Articles/238657/How-to-use-Commands-in-WPF

谢谢

Ajay M


这篇关于从viewModel调用DataGrid.CancelEdit()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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