How to: Access the Bar Manager
- 2 minutes to read
WinForms applications use the Bar Manager to show an application’s menu when the ribbon interface is disabled (see IModelOptionsWin.FormStyle), and to display a nested Frame’s toolbar. This topic describes how to access the Bar Manager. Refer to the How to: Customize Action Controls topic to learn how to customize bar items.
Follow the steps below to access the BarManager object and customize its settings:
- Create a new Controller in the WinForms module’s Controllers folder. This Controller customizes Bar Managers in all Frames, including nested Frames (see NestedFrame).
- Override the Controller’s OnActivated method and subscribe to the Frame.TemplateChanged event.
- In the TemplateChanged event handler, ensure that the Frame.Template‘s type is IBarManagerHolder. Cast the Template to the IBarManagerHolder type and use the IBarManagerHolder.BarManager property to access the BarManager object. For instance, you can set the BarManager.AllowCustomization property to false to prohibit end-users from customizing a bar.
- Override the Controller’s OnDeactivated method and unsubscribe from the TemplateChanged event when the Controller is deactivated.
using System;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Win.Controls;
using DevExpress.XtraBars;
// ...
public class BarManagerCustomizationWindowController : Controller {
protected override void OnActivated() {
base.OnActivated();
Frame.TemplateChanged += Frame_TemplateChanged;
}
private void Frame_TemplateChanged(object sender, EventArgs e) {
if (Frame.Template is IBarManagerHolder) {
BarManager manager = ((IBarManagerHolder)Frame.Template).BarManager;
manager.AllowCustomization = false;
}
}
protected override void OnDeactivated() {
Frame.TemplateChanged -= Frame_TemplateChanged;
base.OnDeactivated();
}
}
Run the application to ensure that bar customization is not allowed.