expressappframework-400495-ui-construction-controllers-and-actions-actions-perform-common-tasks-with-xaf-actions.md
This article describes the most common tasks with XAF Actions.
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.
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.
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.
Information on Actions is available in the Application Model’s ActionDesign node.
You can access Actions and customize them in code.
In XAF, you can create custom Action types and custom controls. See the examples below:
See the articles below to learn how to diagnose and fix the most frequently encountered problems.
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:
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).For more information on how to implement such complex requirements, refer to the following materials: