如何使用 MVVM 取消对对象的编辑? [英] How to cancel an edit to an object using MVVM?
问题描述
如何使用 MVVM 实现取消编辑对象.
例如:我有一个客户列表.我选择一个客户,然后单击编辑"按钮,打开一个对话框窗口(DataContext 绑定到 CustomerViewModel),然后我开始编辑客户的字段.然后我决定取消编辑,但是客户的字段已经改变了,那么我如何在MVVM中将客户恢复到以前的状态?
查看 IEditableObject
接口.您的 Customer
类应该实现它,并且您的命令可以根据需要执行 BeginEdit
/CancelEdit
/EndEdit
.>
How can I implement cancelation of editing an object using 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?
Check out the IEditableObject
interface. Your Customer
class should implement that, and your commands can execute BeginEdit
/ CancelEdit
/ EndEdit
as appropriate.
这篇关于如何使用 MVVM 取消对对象的编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!