Skip to main content
.NET Framework 4.6.2+

ModelEditorGroupingHelper Class

Contains helper methods and properties that you can use to replace or customize the default grouping mechanism in the Model Editor‘s Nodes Tree.

Namespace: DevExpress.ExpressApp.ModelEditor

Assembly: DevExpress.ExpressApp.v24.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public class ModelEditorGroupingHelper

Remarks

The following example demonstrates how to group IModelValidationRules child nodes by a target type’s full name.

  1. In the module’s constructor implemented in the MySolution.Module\Module.cs file, access the ModelEditorGroupingHelper instance (see ModelEditorGroupingHelper.Instance) and call its RegisterNodeGroupPathDelegate. Pass the type of a node you want to regroup (IModelValidationRules) and a delegate with grouping logic (GroupPathCalculatorByNamespace) to this delegate.

    Important

    Do not customize ModelEditorGroupingHelper in multiple modules in the solution to avoid design-time issues in the Model Editor.

  2. In the GroupPathCalculatorByNamespace method, return a string array where each array item is a group in the Node Tree.
  3. Create an array with the UnspecifiedGroupName constant value and return it for nodes whose group path cannot be calculated for the current model node.

File: MySolution.Module\Module.cs.

using DevExpress.ExpressApp; 
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.ModelEditor; 
using DevExpress.ExpressApp.Model.Core;
using DevExpress.ExpressApp.Validation;
// ...
public sealed partial class MySolutionModule : ModuleBase {
    public MySolutionModule() {
        InitializeComponent();
        ModelEditorGroupingHelper.Instance.RegisterNodeGroupPathDelegate(
        typeof(IModelValidationRules), node => GroupPathCalculatorByNamespace("TargetType.FullName", node));
    }
    private static string[] EmptyGroupName = new string[] { ModelEditorGroupingHelper.UnspecifiedGroupName };
    public string[] GroupPathCalculatorByNamespace(string propertyName, IModelNode modelNode) {
        object propertyValue = ModelEditorGroupingHelper.Instance.GetPropertyValue(propertyName, modelNode);
        if(propertyValue != null) {
            string typeName = propertyValue.ToString();
            if(!string.IsNullOrEmpty(typeName)) {
                int lastPointIndex = typeName.LastIndexOf('.');
                if(lastPointIndex > 0) {
                    return new string[] {
                        typeName.Substring(0, lastPointIndex),
                        typeName.Substring(lastPointIndex + 1)
                    };
                }
                else {
                    return new string[] { typeName };
                }
            }
        }
        return EmptyGroupName;
    }
    // ...
}

The following image demonstrates the grouped Validation | Rules nodes:

ModelEditorGroupingHelper

You can apply the same grouping mechanism to other model nodes. The following example demonstrates how to register the GroupPathCalculatorByNamespace mechanism for the IModelViews node in addition to IModelValidationRules.

File: MySolution.Module\Module.cs

using DevExpress.ExpressApp; 
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.ModelEditor; 
using DevExpress.ExpressApp.Model.Core;
// ...
public sealed partial class MySolutionModule : ModuleBase {
    public MySolutionModule() {
        InitializeComponent();
        ModelEditorGroupingHelper.Instance.RegisterNodeGroupPathDelegate(
            typeof(IModelValidationRules), 
            node => GroupPathCalculatorByNamespace("TargetType.FullName", node)
        );
        ModelEditorGroupingHelper.Instance.RegisterNodeGroupPathDelegate(
            typeof(IModelViews), 
            node => GroupPathCalculatorByNamespace("ModelClass.Name", node)
        );
    }
    // ...
}

The following image demonstrates the grouped Views nodes:

ModelEditorGroupingHelper

Note

XAF uses the same mechanism to group the Validation | Rules and Views nodes.

Inheritance

Object
ModelEditorGroupingHelper
See Also