Back to Devexpress

XafApplication.SaveModelChanges() Method

expressappframework-devexpress-dot-expressapp-dot-xafapplication-77633a1a.md

latest3.5 KB
Original Source

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

csharp
public virtual void SaveModelChanges()
vb
Public Overridable Sub 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

csharp
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();
    }
// ...
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SaveModelChanges() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

xaf-how-to-save-the-currently-opened-view-as-a-new-view-variant-at-runtime/CS/XPO/ViewVariantSave/ViewVariantSave.Module/Controllers/UserViewVariantsController.cs#L153

csharp
UpdateUserViewVariantsAction(); //Updates the items of our User View Variant Action based on the current the Change Variant Action structure.
Application.SaveModelChanges();
var cnt = Frame.GetController<ShowNavigationItemController>();

See Also

XafApplication Class

XafApplication Members

DevExpress.ExpressApp Namespace