Skip to main content

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.v25.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public virtual void SaveModelChanges()

Remarks

XAF calls this method when it needs to save user settings. You can call it at any time during the application run. For example, you can implement an Action that allows users to save the changes.

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.Win/Controllers/MyController.cs

using DevExpress.ExpressApp.Win;
// ...
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