Build a Side Navigation UI Used in the DevExpress Demo Center
- 5 minutes to read
This tutorial uses the WinForms Accordion control to create a side navigation menu in a Ribbon Form. The side navigation menu emulates the UI found in the DevExpress Demo Center, which has the following features:
- The menu is always visible
- It shifts the Ribbon UI to the right
- It groups items into categories
- It displays a search/filter box
Set Up the Layout
Create an
AccordionControl
and set theAccordionControl.Dock
property toLeft
.Set the AccordionControl.ViewType property to
Standard
. This value hides UI elements that allow users to expand/collapse the menu.Assign the
AccordionControl
to theRibbonForm.NavigationControl
property.Note
The
NavigationControl
property is hidden from IntelliSense and the Properties window because it is intended for internal use. You should explicitly set theNavigationControl
property in code.using DevExpress.XtraBars.Navigation; AccordionControl accordionControl1; public Form1() { InitializeComponent(); // ... accordionControl1 = new AccordionControl(); accordionControl1.Dock = DockStyle.Left; accordionControl1.OptionsHamburgerMenu.DisplayMode = AccordionControlDisplayMode.Overlay; accordionControl1.ViewType = AccordionControlViewType.Standard; this.NavigationControl = accordionControl1; }
Create Menu Items
At design time, right-click the AccordionControl
to add items. Use an item’s smart tag menu to specify/customize item content.
Tip
Use the Accordion Control’s Designer to build an item hierarchy of any complexity.
The following code snippet creates a group with two items:
void CreateAccordionItems()
{
// Clear items created at design time (optional)
accordionControl1.Elements.Clear();
AccordionControlElement group1 = new AccordionControlElement(ElementStyle.Group)
{
Name = "group1",
Text = "Contacts",
Expanded = true
};
AccordionControlElement item1 = new AccordionControlElement(ElementStyle.Item)
{
Name = "itemCustomers",
Text = "Customers",
};
AccordionControlElement item2 = new AccordionControlElement(ElementStyle.Item)
{
Name = "itemEmployees",
Text = "Employees"
};
// Assign SVG images to Accordion items based on image names in the SVG collection
// 'svgImageCollection1' was populated with SVG images at design time
group1.ImageOptions.SvgImage = svgImageCollection1["contacts"];
item1.ImageOptions.SvgImage = svgImageCollection1["customers"];
item2.ImageOptions.SvgImage = svgImageCollection1["employees"];
group1.Elements.AddRange(new AccordionControlElement[] { item1, item2 });
accordionControl1.Elements.Add(group1);
}
Implement Static Groups
Deactivate the following settings to keep groups always expanded:
accordionControl1.ShowGroupExpandButtons = false;
accordionControl1.ExpandGroupOnHeaderClick = false;
Display a Search/Filter Item
Set the AccordionControl.ShowFilterControl property to Always
to display a search/filter item in the menu:
Display a Fluent Scroll Bar
The Accordion Control displays a vertical scroll bar when the number of items exceeds the visible area. Set the AccordionControl.ScrollBarMode property to Fluent
. This value activates Fluent Design behavior: dynamic display, no arrow buttons, and a smooth transition.
Highlight the Selected Item
Enable the AccordionControl.AllowItemSelection property to highlight the clicked item:
Implement Page Navigation
Add Navigation Pages
Drop a NavigationFrame on the Form and set the NavigationFrame.Dock
property to Fill
. You can add navigation pages at design time or in code (this tutorial adds a Data Grid to each page).
GridControl gridControl1;
RoundedSkinPanel rootPanel1;
NavigationFrame navFrame;
void InitNavigationFrame() {
navFrame = new NavigationFrame();
navFrame.Dock = DockStyle.Fill;
this.Controls.Add(navFrame);
NavigationPage navPageCustomers = new NavigationPage();
NavigationPage navPageEmployees = new NavigationPage();
navFrame.Pages.Add(navPageCustomers);
navFrame.Pages.Add(navPageEmployees);
// Add a Data Grid wrapped in a RoundedSkinPanel to a navigation page
rootPanel1 = new RoundedSkinPanel() {
Dock = DockStyle.Fill
};
navigationPage1.Controls.Add(rootPanel1);
gridControl1 = new GridControl() {
Dock = DockStyle.Fill
};
rootPanel1.Controls.Add(gridControl1);
}
Tip
This tutorial uses a RoundedSkinPanel
to display navigation page controls with rounded corners. Read the following help topic for more information: Grid Lines and Rounded Corners.
Link Menu Items to Pages
Handle the AccordionControl.ElementClick event and change the NavigationFrame.SelectedPage property value based on the clicked item:
void accordionControl1_ElementClick(object sender, ElementClickEventArgs e) {
Dictionary<string, NavigationPage> pages = new Dictionary<string, NavigationPage>() {
["Customers"] = navPageCustomers,
["Employees"] = navPageEmployees
};
navigationFrame1.SelectedPage = pages[e.Element.Text];
}
Apply a Skin
This tutorial applies the WXI skin as follows:
If you wish to add a Ribbon item that allows users to change the skin/palette at runtime, read the following help topic: Add and Customize the Ribbon Skin List and Skin Gallery.