How to: Access the Navigation Dock Panel (in a WinForms Application)
- 2 minutes to read
This topic describes how to access and customize the Dock Panel used to display Navigation in WinForms applications.
Tip
A complete sample project is available in the DevExpress Code Examples database at https://supportcenter.devexpress.com/ticket/details/t275956/how-to-access-the-navigation-dock-panel-in-a-winforms-application.
- Inherit WindowController in the WinForms module project.
- In the constructor, set the WindowController.TargetWindowType property to Main.
- Override the OnActivated method and subscribe to the Frame.TemplateChanged event.
- In the TemplateChanged event handler, cast Frame.Template to Form and subscribe to the Form.Load event.
- In the Load event handler, cast the template to the INavigationPanelHolder type and access the DockPanel object using the DockPanelNavigation property.
The snippet below demonstrates these steps.
using System.Windows.Forms;
using DevExpress.ExpressApp;
// ...
public class HideNavigationPanelButtonsController : WindowController {
public HideNavigationPanelButtonsController() {
this.TargetWindowType = WindowType.Main;
}
protected override void OnActivated() {
base.OnActivated();
Frame.TemplateChanged += Frame_TemplateChanged;
}
private void Frame_TemplateChanged(object sender, EventArgs e) {
Form form = (Form)Frame.Template;
form.Load += Form_Load;
}
private void Form_Load(object sender, EventArgs e) {
if(Frame.Template is DevExpress.ExpressApp.Win.Templates.INavigationPanelHolder) {
DevExpress.XtraBars.Docking.DockPanel navigationPanel =
((DevExpress.ExpressApp.Win.Templates.INavigationPanelHolder)Frame.Template).DockPanelNavigation;
navigationPanel.Options.ShowAutoHideButton = false;
navigationPanel.Options.ShowCloseButton = false;
}
}
protected override void OnDeactivated() {
Frame.TemplateChanged -= Frame_TemplateChanged;
base.OnDeactivated();
}
}
In the code above, the BaseDockOptions.ShowAutoHideButton and BaseDockOptions.ShowCloseButton options are changed. You can use other properties of the DockPanelOptions as well.
Important
You can access the DockPanel object directly in the TemplateChanged event handler, but your settings will be overriden by XAF defaults in this instance. So, use the Form.Loadevent to override defaults.