如何使用MVVM取消对对象的编辑? [英] How to cancel an edit to an object using MVVM?
问题描述
如何使用MVVM取消编辑对象.
How can I implement cancelation of editing an object using MVVM.
例如:我有一个客户列表.我选择一个客户,然后单击按钮编辑",将打开一个对话框窗口(DataContext绑定到CustomerViewModel),然后开始编辑客户的字段.然后我决定取消编辑,但是客户的字段已经更改,那么如何使客户回到MVVM中的先前状态?
For example: I have a list of customers. I choose one customer an click the button "Edit", a dialog window(DataContext is binded to CustomerViewModel) opens and I start editing customer's fields. And then I decide to cancel editing, but the fields of the customer have been already changed, so how can I return a customer to its previous state in MVVM?
推荐答案
查看 IEditableObject
接口.您的Customer
类应该实现这一点,并且您的命令可以根据需要执行BeginEdit
/CancelEdit
/EndEdit
.
Check out the IEditableObject
interface. Your Customer
class should implement that, and your commands can execute BeginEdit
/ CancelEdit
/ EndEdit
as appropriate.
这篇关于如何使用MVVM取消对对象的编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!