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.v24.2.dll
NuGet Package: DevExpress.ExpressApp
Declaration
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 reason(s) why an action should be activated or deactivated. If all the reasons are set to true, the Action is activated. If at least one reason is false, the Action is 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:
- Specify an Action’s or Controller’s properties - ActionBase.TargetObjectType, ActionBase.TargetViewType, ViewController.TargetObjectType and ViewController.TargetViewType. For details, refer to the Define the Scope of Controllers and Actions topic.
- Use the Conditional Appearance Module. Along with the other UI customization capabilities, it allows hiding and showing Actions based on the specified rules, for instance, based on the business objects’ property values. See an example of how to hide an action using this module in the Declare Conditional Appearance Rules in Code topic (a rule with the ActionState ID).
- Use the Security System. Basically, it allows defining the Read, Write, Create, Delete and Navigate permissions for business classes, objects and members. Built-in controllers that perform operations with business objects take these permissions into account when calculating the Active and Enabled states of their actions. For example, the Delete Action is disabled if a user does not have permission to delete the selected objects. You can also implement a similar functionality for your custom Actions (see Use the Security System).
- Specify properties in the Application Model that define the ability to perform different operations with business objects in a View: IModelView.AllowNew, IModelView.AllowDelete, IModelView.AllowEdit, IModelCommonMemberViewItem.AllowClear. These properties affect the Active state of Actions that perform these operations.
- Use the IModelHiddenActions node that allows you to hide an Action from a specific View using the Model Editor.
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.
Related GitHub Examples
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.