Skip to main content
.NET 6.0+

Perform Common Tasks With XAF Actions

  • 5 minutes to read

This article describes the most common tasks with XAF Actions.

Add an Action to a Controller

Note

In .NET Core applications, it is impossible to add an Action to a Controller in the Controller’s Designer because of the changes in Visual Studio’s designer architecture. You can add an Action in code as described below.

If you require an Action that applies to multiple business objects and takes user input, add this Action to a Controller.

You can also add an Action to a Controller in code.

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
// ...
public class CustomViewController : ViewController {
    public CustomViewController() {
        SimpleAction customAction = new SimpleAction(this, "CustomAction", PredefinedCategory.View);
        // or
        customAction.Category = PredefinedCategory.View.ToString();
        // or 
        customAction.Category = "View";
        // or 
        customAction.Category = "MyCustomCategory";
    }
}

After you add an Action to a Controller, you can use the Designer to customize the Action.

Note

CodeRush allows you to add Actions and Controllers with a few keystrokes. To learn about the Code Templates for XAF, refer to the following help topic: XAF Templates.

Add an Action by Applying the Action Attribute to a Business Class Method

If you require an Action that applies to one business object and uses the business object’s parameters, apply the Action attribute to the business class’s method as shown below:

Use the Action attribute only for simple scenarios similar to those described in the articles. For greater flexibility, you can add an Action to a Controller.

Use Action Settings

The base class for all Action types is the ActionBase class. This class exposes events, properties, and methods that support the common Action behavior.

Events

Properties

Tip

Access the ActionBase class’s members page for a complete list of available API.

Customize an Action in the Application Model

Information on Actions is available in the Application Model’s ActionDesign node.

Customize an Action in Code

You can access Actions and customize them in code.

Create Custom Action Types and Custom Controls

In XAF, you can create custom Action types and custom controls. See the examples below:

Troubleshoot Actions

See the articles below to learn how to diagnose and fix the most frequently encountered problems.

Execute Actions Programmatically

We do not recommend that you use the DoExecute and other methods to execute Actions because such methods can contain UI-specific code. You can refactor your Action’s event handlers and extract the required code into separate methods. Call these separate methods directly without triggering UI-related Action code.

Programmatic execution of custom and built-in Actions is acceptable in rare advanced scenarios, for example, if you:

  • Create a custom Action Container and call the DoExecute method inside the Action control. In this context, you have complete control over your custom code and can execute any action. Remember to trigger life-cycle events for your actions (such as Execute).
  • Add new ways to invoke Actions from the UI (for example, support keyboard or voice control).
  • Reuse a built-in Action in a specific context where you would need to write a lot of code to re-implement the Action’s internal business logic.

For more information on how to implement such complex requirements, refer to the following materials: