How to cancel an edit to an object using MVVM?

后端 未结 7 1533
既然无缘
既然无缘 2020-12-01 08:34

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 dialo

相关标签:
7条回答
  • 2020-12-01 09:04

    In this article, Raul just reload the object from the DB. I guess it's less trouble than the solution Kent proposes.

        internal void Cancel(CustomerWorkspaceViewModel cvm)
        {
            Mainardi.Model.ObjectMapping.Individual dc = cvm.DataContext 
                                     as Mainardi.Model.ObjectMapping.Individual;
    
            int index = 0;
    
            if (dc.ContactID > 0 && dc.CustomerID > 0)
            {
                index = _customerCollectionViewModel.List.IndexOf(dc);
                _customerCollectionViewModel.List[index] = 
                                      _customerBAL.GetCustomerById(dc.CustomerID);
            }
    
            Collection.Remove(cvm);
        }
    
    0 讨论(0)
提交回复
热议问题