ListEditor.CreateCustomModelSynchronizer Event

Obsolete. Occurs when the Application Model's node specified by the ListEditor.Model property has been changed.

Namespace: DevExpress.ExpressApp.Editors

Assembly: DevExpress.ExpressApp.v18.1.dll

Syntax

[Obsolete("Use the ModelApplying/ModelApplied/ModelSaving/ModelSaved events or override the ApplyModel/SaveModel methods instead.")]
public event EventHandler<CreateCustomModelSynchronizerEventArgs> CreateCustomModelSynchronizer

The event handler receives an argument of the CreateCustomModelSynchronizerEventArgs type. The CreateCustomModelSynchronizerEventArgs properties provide information specific to this event.

To ensure correct operation, each built-in List Editor overrides the protected ListEditor.CreateModelSynchronizer method, to create a specific object used to persist the configuration of the List Editor's control into the Application Model. This object is called model synchronizer, and its methods are invoked by XAF via the ListEditor.ApplyModel and ListEditor.SaveModel methods. If you need to persist additional information on the List Editor's control into the Application Model, you can specify an additional custom model synchronizer to be used by a built-in List Editor by handling its ListEditor.CreateCustomModelSynchronizer event.

To create a custom model synchronizer, declare a class derived from the ModelSynchronizer<T, V>. Override the protected ApplyModelCore method to check the ModelSynchronizer`2.Model property and configure the ModelSynchronizer`2.Control accordingly. Override the ModelSynchronizer.SynchronizeModel method to check the Control property, and configure the Application Model via the Model property accordingly. When instantiating the model synchronizer instance in the CreateCustomModelSynchronizer event handler, pass a reference to the List Editor and the Application Model node specified by the ListEditor.Model property into the model synchronizer.

using DevExpress.XtraGrid;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Core;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Win.Editors;
//...
public class MyViewController : ViewController<ListView> {
    protected override void OnActivated() {
        base.OnActivated();
        if (View.Editor is GridListEditor) {
            View.Editor.CreateCustomModelSynchronizer += Editor_CreateCustomModelSynchronizer;
        }
    }
    protected override void OnDeactivated() {
        if (View.Editor is GridListEditor) {
            View.Editor.CreateCustomModelSynchronizer -= Editor_CreateCustomModelSynchronizer;
        }
        base.OnDeactivated();
    }
    void Editor_CreateCustomModelSynchronizer(object sender, 
        CreateCustomModelSynchronizerEventArgs e) {
        e.ModelSynchronizer = 
            new MyModelSynchronizer(((GridListEditor)sender).Grid, (IModelListView)e.Model);
    }
}
public class MyModelSynchronizer : ModelSynchronizer<GridControl, IModelListView> {
    public MyModelSynchronizer(GridControl gridControl, IModelListView model) : 
        base(gridControl, model) { }  
    protected override void ApplyModelCore() {
        //Check the MyModelSynchronizer.Model property and 
        //configure the MyModelSynchronizer.Control accordingly
    }        
    public override void SynchronizeModel() {
        //Check the MyModelSynchronizer.Control property and 
        //configure the MyModelSynchronizer.Model accordingly
    }
}