Skip to main content
.NET 6.0+

ActionBase.TargetObjectsCriteria Property

Specifies a logical expression (criteria) for enabling an Action.

Namespace: DevExpress.ExpressApp.Actions

Assembly: DevExpress.ExpressApp.v24.1.dll

NuGet Package: DevExpress.ExpressApp

Declaration

[DefaultValue(null)]
public string TargetObjectsCriteria { get; set; }

Property Value

Type Default Description
String null

A string value representing a logical expression (criteria).

Remarks

This property allows defining for what objects an Action will be enabled or disabled. A disabled Action is visible in the UI, but it is grayed out and cannot be executed. Specify a logical expression built in accordance with the Criteria Language Syntax there, and the Action will be enabled only for objects that fit this expression. The Action should be added in a View Controller - Actions created in other Controller types are not affected by this property.

Note

The TargetObjectsCriteria property has an effect only if the ActionBase.SelectionDependencyType property is set to RequireSingleObject or RequireMultipleObjects. The manner in which an Action’s enabled state is calculated when several objects are selected is determined by the ActionBase.TargetObjectsCriteriaMode property.

You can set the value of the TargetObjectsCriteria property in code, in the Controller’s designer or in the Model Editor. This value will be saved to the IModelAction.TargetObjectsCriteria property of the Application Model’s ActionDesign | Actions | <Action> node. The following image demonstrates how the TargetObjectsCriteria property is specified in the Model Editor:

WaysToBuildCriteria

This criteria expression uses the LocalDateTimeToday function criteria operator. The following Controller demonstrates how to specify the TargetObjectsCriteria property in code. This Controller enables the Action when the selected Task‘s DueDate property value is less than or equal to the system’s date and time:

public class MyController : ViewController {
    public MyController() {
        TargetObjectType = typeof(Task);
        SimpleAction myAction = new SimpleAction(this, "MyAction", DevExpress.Persistent.Base.PredefinedCategory.Unspecified);
        myAction.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
        myAction.TargetObjectsCriteria = "DueDate <= LocalDateTimeToday()";
    }
}

The TargetObjectsCriteria property is appropriate for Actions displayed only for specific business object types. If an Action is displayed for a type that does not have properties specified in the TargetObjectsCriteria expression, an exception will be thrown. That is why if you wish to define the TargetObjectsCriteria for an Action that can be displayed for multiple types (e.g., for one of the built-in actions), do this dynamically in code when a View of the required type is displayed, and clear the passed value when this View is closed:

public class MyController : ViewController {
    public MyController() {
        TargetObjectType = typeof(Department);
    }
    DeleteObjectsViewController deleteController;
    protected override void OnActivated() {
        base.OnActivated();
        deleteController = Frame.GetController<DeleteObjectsViewController>();
        if (deleteController != null) {
            deleteController.DeleteAction.TargetObjectsCriteria = "Contacts.Count = 0";
            deleteController.DeleteAction.TargetObjectsCriteriaMode = TargetObjectsCriteriaMode.TrueForAll;
        }
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        if (deleteController != null) {
            deleteController.DeleteAction.TargetObjectsCriteria = null;
            deleteController.DeleteAction.TargetObjectsCriteriaMode = default(TargetObjectsCriteriaMode);
            deleteController = null;
        }
    }
}
See Also