Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

ActionBase.Active Property

Gets a collection of reason/value pairs used to determine or change the Action‘s active state. The resulting state determines the Action’s visibility.

Namespace: DevExpress.ExpressApp.Actions

Assembly: DevExpress.ExpressApp.v20.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

[Browsable(false)]
public BoolList Active { get; }

Property Value

Type Description
BoolList

A BoolList object that represents a collection of key/value elements.

Remarks

The Active property contains key/value pairs with the reasons why an action should be activated or deactivated. If all reasons are set to true, an Action will be activated. If there is at least one reason whose value is false, an Action will be deactivated. An inactive Action is invisible and cannot be executed.

Note

To disable (gray out) an Action instead of hiding it, use the ActionBase.Enabled property.

Keys and values can be added to the Active BoolList for various sources. For instance, the value with the “Controller active” key determines whether or not a Controller to which this Action is added is active. Thus, if an Action’s Controller is inactive, this Action will be inactive as well. At the same time, although this parameter is set to true, the Active list may contain an item added by another source that deactivates the Action for another reason. E.g., the Security System may deactivate an Action because the current user does not have proper permissions.

Except for values written by XAF, you can add your own key/value items to the Active list to manage the Action’s visibility. To deactivate an Action, add an item with the false value to this list. To subsequently activate the Action, either remove the previously added item using the BoolList.RemoveItem method, or set the value of this item to true.

Example 1

The example below shows how to set a Contact‘s FirstName value to the NickName property and deactivate the SimpleAction.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using MainDemo.Module.BusinessObjects;
// ...
public class SetNickNameController : ObjectViewController<DetailView, Contact> {
    private SimpleAction setNickNameAction;
    public SetNickNameController() {
        setNickNameAction = new SimpleAction(this, "SetNickName", PredefinedCategory.Edit);
        setNickNameAction.Execute += SetNickNameAction_Execute;
    }
    private void SetNickNameAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        Contact currentObject = ViewCurrentObject;
        if(currentObject != null) {
            currentObject.NickName = currentObject.FirstName;
            setNickNameAction.Active["ActionExecuted"] = false;
        }
    }
}

Example 2

The following example demonstrates how to deactivate an Action when the View.AllowNew property is false.

public class ViewController1 : ViewController {
    SimpleAction action1;
    public ViewController1() {
        action1 = new SimpleAction(this, "Create Object", DevExpress.Persistent.Base.PredefinedCategory.ObjectsCreation);
    }
    protected override void OnActivated() {
        base.OnActivated();
        action1.Active["ViewAllowsNew"] = View.AllowNew;
    }
}

To see another example of using the Active property, refer to the How to: Deactivate (Hide) an Action in Code topic.

Note

Do not change Active items that are not added from your code. If you need to change the value of such an item, determine under what condition this item is added and change this condition. Refer to the Determine Why an Action, Controller or Editor is Inactive topic for additional information.

Ways to Change the Active State

It is not always necessary to access the Active BoolList directly to hide an Action. In many situations, it is more convenient to define a rule or condition based on which an Action should be activated. Here are the most common ways to do this:

To use these approaches, you may need to know the identifiers of Actions which you want to hide and the Controllers to which they belong. Refer to the Determine an Action’s Controller and Identifier topic to learn how to do this.

The following code snippets (auto-collected from DevExpress Examples) contain references to the Active property.

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.

See Also