expressappframework-112610-ui-construction-action-containers.md
Action Containers are UI placeholders that display Actions (commands and buttons) in an XAF application. They determine where actions appear, such as toolbars, menus, ribbons, and context menus. Templates control where containers appear on screen.
You interact with Action Containers when you want to reorganize your application’s command UI, create custom toolbars, or control where specific actions appear:
XAF creates Action Containers automatically when it initializes a Template. The process consists of the following steps:
Example (Windows Forms):
BarButtonItem button controlBarEditItem dropdown controlThe following images show Action Container placement in ASP.NET Core Blazor application UI:
Tip
For more information about Actions in grid columns in ASP.NET Core Blazor applications, refer to the following topic: How to: Add a Grid Column with an Action (ASP.NET Core Blazor).
When to use: Move Actions between existing containers (toolbars/menus) or delete Actions at design time or runtime.
For a detailed scenario, refer to the following topic: How to: Place an Action in a Different Location.
For more information about this Application Model node, refer to the IModelActions interface description.
When to use: Apply conditional logic or dynamic behavior that cannot be configured in the Application Model.
| API | Use |
|---|---|
| Frame.ProcessActionContainer | Use event’s properties to customize Action Container |
| IActionContainer.Actions | Access Actions of a particular Action Container and customize these Actions. For example, you can toggle an Action’s ActionBase.Active property to deactivate this Action. You can also access an Action’s control and customize it. |
| ActionBase.CustomizeControl | Customize an Action Control. For a detailed scenario, refer to the following topic: How to: Customize Action Controls |
| ActionControlsSiteController.CustomizeContainerActions | Customize the action-to-container mapping in code. |
When to use:
Important
Drop-down menus do not support ParametrizedAction and SingleChoiceAction when ItemType is set to SingleChoiceActionItemType.ItemIsMode.
| Property | Description |
|---|---|
isDropDown | Specifies whether the container’s Actions are grouped into a drop-down list. |
defaultActionId | Specifies the root menu Action’s identifier. |
autoChangeDefaultAction | Specifies whether the last executed Action becomes the default one. |
imageName | Specifies the image used as the root menu item. |
caption | Specifies the caption used as the root menu item. |
Tip
defaultActionId, imageName, and caption parameters, XAF displays the first Action as the root item.The following code snippet demonstrates the recommended approach (using an Action as the root item). Two alternative approaches are shown as comments.
File: MySolution.Blazor.Server/Templates/CustomApplicationWindowTemplate.cs
using DevExpress.Blazor;
using DevExpress.ExpressApp.Blazor.Templates;
namespace MySolution.Blazor.Server {
public class CustomApplicationWindowTemplate : ApplicationWindowTemplate {
public CustomApplicationWindowTemplate() {
// Action as the root item
Toolbar.AddActionContainer("SaveOptions", alignment: ToolbarItemAlignment.Right, isDropDown: true, defaultActionId: "SaveAndNew", autoChangeDefaultAction: true);
// Image as the root item
// Toolbar.AddActionContainer("SaveOptions", alignment: ToolbarItemAlignment.Right, isDropDown: true, imageName: "Save");
// Caption as the root item
// Toolbar.AddActionContainer("SaveOptions", alignment: ToolbarItemAlignment.Right, isDropDown: true, caption: "Save Options");
}
}
}
OnActivated method to access the BlazorRibbonController and subscribe to its RibbonActionContainerCreating event. This event fires when the controller generates a DxRibbon Action Container model.The following code snippet:
SaveOptions Container in a drop-down menuWhen to use: Replace the default controls with custom UI components (advanced scenario).
Inherit from the desired platform control and implement the IActionContainer interface. Alternatively, you can inherit your custom container from one of the existing Action Containers. You may also need to specify the controls XAF should use for each Action type.
After you declared your own Action Container, create a new Template or customize an existing template as described in the following topics:
Add your Action Container to the Template and add your Action Container’s instance to the list returned by the Template’s IFrameTemplate.GetContainers method.
Tip
If you have XAF sources installed, you can see how built-in Action Containers are implemented in the following locations:
| API | Description |
|---|---|
| Category | Specifies the Action Container where XAF displays the current Action. |
| ContextMenuTemplate | Offers access to a List Editor’s Context Menu Template. |
| CustomizeContainerActions | Fires when Actions are added to the Action Containers. |
See Also
Controllers (UI Logic & Interaction)
GitHub Example: XAF - Add Custom Buttons (Actions) to Lookup and Popup Windows