ActionBase.Enabled Property
Provides access to a collection of key/value pairs used to determine an Action‘s enabled/disabled state. A Disabled Action is visible in the UI, but it is grayed out and cannot be executed.
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 Enabled property contains key/value pairs with the reasons why an Action should be enabled or disabled. If all reasons are set to True, an Action will be enabled. If there is at least one reason with the false value, an Action will be disabled.
Note
To hide an Action instead of disabling it, use the ActionBase.Active property.
Values can be added to the Enabled list from various sources. For example, a certain Controller may add a false value to this list. In this case, even if another Controller adds the true value to this list, the Action will be disabled until the first Controller changes the corresponding Enabled list item. You can add your own enabled or disabled reasons to the Enabled list. To disable an Action, add an item with the false value. To subsequently enable the Action , either remove the previously added item using the BoolList.RemoveItem method, or set the value of this item to true. Refer to the BoolList topic for additional information.
Example 1
The example below shows how to assign a Contact‘s FirstName value to the NickName property and disable 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.Enabled["DisableAfterExecution"] = false;
}
}
}
Example 2
The following example demonstrates how to disable an Action when the View.AllowEdit property returns false.
public class ViewController1 : ViewController {
SimpleAction action1;
public ViewController1() {
action1 = new SimpleAction(this, "Edit Object", DevExpress.Persistent.Base.PredefinedCategory.RecordEdit);
}
protected override void OnActivated() {
base.OnActivated();
action1.Enabled["ViewAllowsEdit"] = View.AllowEdit;
}
}
To see other examples of using the Enabled property, refer to the Add a Simple Action using an Attribute and How to: Disable an Action When the Current View Has Unsaved Changes topics.
Note
Changing Enabled items added by other sources manually is not recommended. If you need to change the value of such an item, find out 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 Enabled State
In the above section, how to disable Actions by changing their Enabled property in code is described. Although this approach is flexible and can be applied in any case, there are easier ways to change the Enabled state conditionally:
- Specify the Action’s ActionBase.TargetObjectsCriteria and ActionBase.SelectionDependencyType properties. When conditions specified in these properties are not met, an Action is disabled. Refer to these properties descriptions for additional information.
- Use the Conditional Appearance module. Along with the other UI customization capabilities, it allows enabling and disabling actions based on the specified rules, for example, depending on business object properties. See an example of how to customize an Action using this module in the Declare Conditional Appearance Rules in Code topic - find a rule with the ActionState ID there.
To use these approaches, you may need to know the identifiers of Actions which you want to disable 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 Enabled 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.