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 |
---|---|
Adds/inserts a Bar to the Bar
Attached properties:
| |
Bar | Adds/inserts a bar item to the Bar A link is created if the Bar
Attached properties:
|
Bar | Adds/inserts a bar item link to the Links collection of a specific link holder (a bar, menu, etc).
Attached properties:
|
Adds a bar to the Bar | |
Adds a bar item to the Bar | |
Adds a bar item link to the link container (a bar, menu, etc). | |
Creates four Bar | |
Inserts a bar at a specific position within the Bar | |
Inserts a bar item at a specific position within the Bar | |
Inserts a bar item link to the item link collection of a target object (a bar, menu, etc). | |
Inserts a bar at a specific position within the Bar | |
Inserts a bar at a specific position within the Bar | |
Removes a bar from the Bar | |
Removes a bar item from the Bar | |
Removes a bar item from the Bar | |
Removes a specific link from the bar item link collection of a target object (a bar, menu, etc). | |
Replaces a bar at a specific position within the Bar | |
Replaces a bar item at a specific position within the Bar | |
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.