Skip to main content

Customizing Bars via Actions

  • 5 minutes to read

 

You can define the structure of bars in two ways:

  • Directly between the BarManager start and end tags. With this approach, you define an explicit hierarchical structure of bar objects (Bar, BarItem and BarItemLink objects).
  • Using bar customization actions, which are dedicated objects capable of creating bars, bar items and bar item links, or modifying the existing structure of a BarManager object.

    Actions are defined separately from a BarManager object, and then simply linked to the BarManager. Typically, multiple actions are required to modify/create the structure of bars, and the actions are put together into a linear list in resources. The BarManager executes the actions, applying them to the current structure of bar objects.

    Since actions can be defined in resources, they can be shared between multiple windows or even applications (if actions are defined in the resources of a DLL library). For instance, you can define actions that create a bar, say MyBar, with some bar items. If these actions are linked to a BarManager, they will be executed (by default, after the BarManager's own bars are initialized) and the new MyBar with its items will be added to the existing structure of bars.

#Actions

Actions are objects that implement the IBarManagerControllerAction interface. All the actions have an internal 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 Bar class and all descendants of the BarItem and BarItemLink classes implement the IBarManagerControllerAction interface. So, these objects can serve as actions.

The following table lists the available actions and attached properties supported by the actions:

Action

Description

Bar

Adds/inserts a Bar to the BarManager.Bars collection.

 

Attached properties:

  • InsertBarAction.BarIndex - Allows you to specify the position at which a bar is inserted to the BarManager.Bars collection. If this property is omitted, the bar is appended to the bar collection.

BarItem class descendants

Adds/inserts a bar item to the BarManager.Items collection, and optionally allows you to create a link for the bar item and add/insert it to a target link holder (a bar, menu, etc)

A link is created if the BarItemLinkActionBase.Target or BarItemLinkActionBase.TargetType attached property is specified.

 

Attached properties:

  • InsertBarItemAction.ItemIndex - Allows you to specify the position at which a bar item is inserted to the BarManager.Items collection. If this property is omitted, the item is appended to the item collection.
  • BarItemLinkActionBase.Target - Allows you to specify the name of target link holder to which the created link is added. The Target property is in effect when the TargetType attached property is not specified or set to Other.
  • BarItemLinkActionBase.TargetType - Allows you to specify the type of the target link holder to which the created link is added.
  • BarItemLinkActionBase.ItemLinkIndex - Allows you to specify the position at which the created link is inserted to the target link holder. If this property is omitted, the link is appended to the link holder's link collection.

BarItemLinkBase class descendants

Adds/inserts a bar item link to the Links collection of a specific link holder (a bar, menu, etc).

 

Attached properties:

  • BarItemLinkActionBase.Target - Allows you to specify the name of target link holder to which the link is added. The Target property is in effect when the TargetType attached property is not specified or set to Other.
  • BarItemLinkActionBase.TargetType - Allows you to specify the type of the target link holder to which the link is added.
  • BarItemLinkActionBase.ItemLinkIndex - Allows you to specify the position at which the link is inserted in the target link holder. If this property is omitted, the link is appended to the link holder's link collection.

AddBarAction

Adds a bar to the BarManager.Bars collection.

AddBarItemAction

Adds a bar item to the BarManager.Items collection.

AddBarItemLinkAction

Adds a bar item link to the link container (a bar, menu, etc).

CreateStandardLayoutAction

Creates four BarContainerControls at the four edges of the window, allowing you to dock bars to the window. See the BarManager.CreateStandardLayout topic to learn more.

InsertBarAction

Inserts a bar at a specific position within the BarManager.Bars collection.

InsertBarItemAction

Inserts a bar item at a specific position within the BarManager.Items collection.

InsertBarItemLinkAction

Inserts a bar item link to the item link collection of a target object (a bar, menu, etc).

InsertMainMenuIfNotExistAction

Inserts a bar at a specific position within the BarManager.Bars collection and sets the Bar.IsMainMenu flag for it. The action does nothing if there already exists a bar with this flag enabled.

InsertStatusBarIfNotExistAction

Inserts a bar at a specific position within the BarManager.Bars collection and sets the Bar.IsStatusBar flag for it. The action does nothing if there already exists a bar with this flag enabled.

RemoveBarAction

Removes a bar from the BarManager.Bars collection.

RemoveBarItemAction

Removes a bar item from the BarManager.Items collection.

RemoveBarItemAndLinkAction

Removes a bar item from the BarManager.Items collection, and removes all links to this bar item from link holders (bars, sub-menus, menus, etc).

RemoveBarItemLinkAction

Removes a specific link from the bar item link collection of a target object (a bar, menu, etc).

SetBarAction

Replaces a bar at a specific position within the BarManager.Bars collection with another bar.

SetBarItemAction

Replaces a bar item at a specific position within the BarManager.Items collection with another bar item.

SetBarItemLinkAction

Replaces a bar item link at a specific position within a target object (bar, menu, etc) with another bar item link.

Actions are typically combined into a BarManagerActionContainer object, and declared within a DataTemplate object in resources.

#Example - Defining Actions

#Executing Actions

To apply actions stored in a BarManagerActionContainer object declared within a DataTemplate, to a BarManager, add a TemplatedBarManagerController object to the BarManager.Controllers collection. Set the TemplatedBarManagerController.Template property so that it refers to the defined DataTemplate. An example is shown below.

By default, actions are executed after the bar structure of the BarManager has been initialized. To execute the actions before the bar structure of the BarManager is initialized, set the BarManagerControllerBase.ExecuteBefore of the TemplatedBarManagerController object to true.

#Example - Executing Actions