Skip to main content
All docs
V24.1

Change the Application Model

  • 2 minutes to read

Use the Model Editor

The Application Model may set settings on multiple levels. You can examine and edit settings on any level that uses a XAFML file. This includes all layers but level zero (settings generated based on Business Model code).

To edit settings on any of those levels, use the Model Editor.

ModelEditorDesign

Get or Set Model Settings in Code

You can access the Application Model in code and either read or modify the required values.

Important

Note that the UI does not immediately reflect changes made in the Application Model. If you need to apply changes after XAF creates and initializes a UI control, access the control directly. See How to: Access the Grid Component in a List View for more information. You can also recreate a control with the latest Application Model changes as described in the following article: Apply Application Model Changes to the Current View Immediately.

To access the Application Model in code, use the following objects:

Object Property
View View.Model
ActionBase ActionBase.Model
PropertyEditor PropertyEditor.Model
XafApplication XafApplication.Model

These properties return an IModelNode descendant that encapsulates the corresponding node. You can use the Application property to access the Application Model’s root node. Refer to the following topic for additional information: How the XAF Application Model Works.

The following code shows how to access the ‘Contact’ business class and modify its IModelClass.Caption:

using System.Linq;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;

namespace YourSolutionName.Module.Controllers {
    public class CustomController : ViewController {
        public CustomController() {
            var myAction1 = new SimpleAction(this, "MyAction1", null);
            myAction1.Execute += MyAction1_Execute;
        }

        private void MyAction1_Execute(object sender, 
         SimpleActionExecuteEventArgs e) {
            var lst = Application.Model.BOModel.ToList();
            var bo = Application.Model.BOModel.Where(x => x.Name == 
             "YourSolutionName.Module.BusinessObjects.Contact").FirstOrDefault();
            if(bo != null) {
                var oldCaption = bo.Caption;
                bo.Caption = "New test caption";
            }
        }
    }
}