Skip to main content
.NET Framework 4.5.2+

XafApplication.SaveModelChanges() Method

Saves the changes made by an end-user, up to the current moment, to the differences storage.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v21.2.dll

Declaration

public virtual void SaveModelChanges()

Remarks

By default, this method is called when the application is closed. So, all the changes made from the application start until the end are saved to the Model.User.xafml file. You can call this method at any time during the application run. For instance, you can implement an Action that allows end-users to save the changes made, up to the current moment.

Note

Since end-user changes are only saved in Windows Forms applications, do not use this method in ASP.NET Web applications.

You can save user changes to another storage; for example, to the database. For this purpose, handle the XafApplication.CreateCustomUserModelDifferenceStore event.

Example

The code below saves the current application state:

File: MySolution.Module.Win/Controllers/MyController.cs(.vb)

using DevExpress.ExpressApp.Win;

namespace SolutionName.Module.Win.Controllers {
    public class MyController : ViewController //or WindowController
    // ...
        private void action_Execute(object sender, SimpleActionExecuteEventArgs e) {
            // Save Model settings in all opened windows in a WinForms application.
            foreach(Frame frame in ((WinShowViewStrategyBase)Application.ShowViewStrategy).Windows) {
                frame.SaveModel();
                // OR
                // frame.View.SaveModel();
            }

            // OR
            // Save Model settings only in the main application window.
            // Application.MainWindow.SaveModel();

            // Save the latest Model settings to a Model difference storage.
            Application.SaveModelChanges();
        }

    // ...
    }
}
See Also