[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Collapse]Ribbon, Bars and Menu
   [Expand]Common Features
   [Collapse]Bars
    [Expand]Getting Started
    [Expand]Bar Layout
    [Expand]Populating Bars
     Bar Actions
    [Expand]Runtime Customization
    [Expand]Examples
     Saving and Restoring a Bar Layout
   [Expand]Ribbon
   [Expand]Menus
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Bar Actions

The bar actions allow you to change existing ribbons, toolbars, and menus in the DevExpress (like Spreadsheet, RichEdit, and others) controls and your custom UserControls.

The bar actions allow you to make the following changes:

  • add new elements
  • replace the existing elements
  • remove default elements
  • update properties for the existing elements.

Expanded Element Actions

Bar actions implement the IControllerAction interface. All actions have the Execute method that implements the action's functionality. When a list of actions is executed, the Execute method is called for every action, in the order defined by the list.

The following classes implement the IControllerAction interface and you can use them as actions:

The table below lists the available scenarios for the elements mentioned above.

Action

Description

Bar

Adds/inserts a Bar to any of the following collections:

BarItem class descendants

 

BarItemLinkBase class descendants

Adds/inserts an element to any of the following collections:

RibbonPageCategoryBase

Adds/inserts an element to the RibbonControl.Categories collection.

RibbonPage

Adds/inserts an element to the RibbonPageCategoryBase.Pages collection.

RibbonPageGroup

Adds/inserts an element to the RibbonPage.Groups collection.

You can configure the bar actions with the following attached properties:

Property

Description

CollectionAction.ContainerName

Use this property to specify the name of the container to which you want to add an element.

For example, to add an additional RibbonPageCategory (see RibbonPageCategory) to the diagram's ribbon, set this property to the DefaultBarItemNames.Ribbon as follows:

CollectionAction.Container

Specifies the container to which a collection action adds an element.

Use this property if you have access to the container instance.

CollectionAction.Index

Use this property to specify the zero-based index at which an element should be inserted.

CollectionAction.CollectionTag

A container can have multiple collections of the required type. Use this property to specify a collection to which the bar action is applied.

Use this property when you add a BarItem (see BarItem) or BarItemLink (see BarItemLink) object to the RibbonControl (see RibbonControl) or RibbonStatusBarControl (see RibbonStatusBarControl).

For example, to add a BarButtonItem (see BarButtonItem) to the RibbonControl.PageHeaderItems collection, set the CollectionAction.CollectionTag property to the PageHeaderItems value:

You can find the full list of the supported collection tags in the RibbonCollections enumeration.

Expanded Collection Actions

The bar actions include the CollectionAction to modify collections of Ribbon, Toolbars, and Menus.

You can use collection actions to insert, remove or replace an item in the collection.

The table above lists the attached CollectionAction properties. The table below describes the CollectionAction properties used to modify collections:

Property

Description

Kind

Specifies the kind of the action. You can choose one of the following values:

  • Insert
  • Remove
  • Replace

You can use the CollectionAction class descendants to make your markup more clear:

ElementName

Specifies the name of an element which you want to add to a container.

Element

Use this property to specify the element to which you want to add a container. The InsertAction (see InsertAction) and ReplaceAction (see ReplaceAction) use the Element property as their content property:

Expanded Update Action

You can use the UpdateAction (see UpdateAction) to modify CLR or dependency property values of Ribbon, Toolbars, and Menus.

For example, use this action to change item headers or bind their properties to your ViewModel.

The following table lists the UpdateAction (see UpdateAction)'s properties:

Property

Description

ElementName

Specifies a name of an element which property the UpdateAction changes.

Element

Specifies an element which property the UpdateAction changes. Use this property if you have access to an element instance.

Property

Specifies a dependency property the UpdateAction changes:

PropertyName

Specifies the name of the CLR or dependency property the action changes.

The UpdateAction uses the Reflection API to set value for the property specified in this way.

Value

Sets a value the action applies to the updated property.

ValueBinding

Sets a data binding the action applies to the updated dependency property specified by the UpdateAction.Property property.

The binding uses the inheritance context of an element that is specified by this UpdateAction.

Expanded Execute Actions

Execute Bar Actions With Built-In Properties

The controls that contain built-in ribbon, toolbars, and menus provide properties useful to define bar actions, such as:

In most cases, you can use the built-in control *Customizations property to customize the toolbars, ribbon, and menu.

Tip

Refer to the following GitHub example for information on how to customize built-in menus: How to access and remove rows by using a custom cell's context menu.

Execute Bar Actions With ControllerBehavior

Use the ControllerBehavior to execute bar actions in custom conditions:

Property

Description

ExecutionMode,

NewActionExecutionMode

Specifies how to execute the bar actions: manually, on event, or on associated object changing.

Triggers

Use this property to specify when to trigger the behavior.

Actions

A collection of actions executed by the behavior.

The code sample below demonstrates how to perform the following actions when the Loaded event occurs:

  • Insert the MyNewlyAddedButton button into the File menu item.
  • Remove the Edit menu item.
  • Add the MyNewlyAddedButton button to the toolbar.

The image below illustrates the result.

Is this topic helpful?​​​​​​​