Accordion Control
- 5 minutes to read
Overview | |
The AccordionControl extends the capabilities of the NavBarControl for creating navigation menus. The control’s items can be combined into groups. Groups can contain nested groups, so you can create an advanced navigation hierarchy. Features include:
|
Accordion Elements
All elements within the accordion control are AccordionControlElement class objects. You can add elements to the AccordionControl using the control’s context menu and smart tags.
Additionally, the AccordionControl’s Designer provides means to manipulate the control elements.
To access root elements in code, use the AccordionControl.Elements collection.
Depending on the AccordionControlElement.Style property value, an element is considered either a group or an item (see below). There are multiple settings common to both group and item elements.
Headers. Items and groups have headers that display an image (AccordionControlElementBase.Image or AccordionControlElementBase.ImageIndex) and text (AccordionControlElementBase.Text). Use the AccordionControlElementBase.TextPosition property to specify whether the image is located before or after text.
Header Controls. The AccordionControl elements can display custom controls in their header areas. To add such a control, assign it to the element’s AccordionControlElementBase.HeaderControl property.
- Header visibility. The AccordionControlElementBase.HeaderVisible property allows you to hide an element’s header. In this case, only the element’s contents are displayed.
- Header layouting. By default, content blocks in all accordion element headers are arranged in the same ‘image - caption - header control - custom buttons’ order. Refer to the Element Header Layout article to learn how to modify this default sequence and re-arrange header content blocks.
Context Buttons. You can display context buttons in item and group headers. Use the AccordionControl.ItemContextButtons and AccordionControl.GroupContextButtons properties, and the AccordionControl.ContextButtonCustomize event optionally to accomplish this task. To specify context buttons for individual elements only, use the AccordionControlElementBase.ContextButtons collection.
- Expand modes. The AccordionControl.ExpandElementMode property is in effect for groups and the items that have content containers associated with them. This property specifies whether single or multiple elements can be expanded simultaneously.
However, certain element properties may be ignored depending on whether this element is a group or an item. For instance, groups can only display other groups and items, so the AccordionControlElementBase.ContentContainer property has no effect on groups. Vice versa, items can display custom content and cannot have child elements; thus, the AccordionControlElement.Elements collection is not in effect for items.
Groups
A group is an AccordionControlElement object of the Group style. It is an expandable element that can only display items and other groups. Thus, you can create a navigation hierarchy consisting of multiple levels using groups. The following image shows the Properties group. It has three immediate children.
Group elements can be accessed using the AccordionControlElement.Elements collection. For elements of the Item style, this property is ignored.
At design time, you can add elements to a group using its smart tag.
Unlike items, groups cannot be associated with content containers. Thus, the AccordionControlElementBase.ContentContainer property and the AccordionControl.GetContentContainer event are not in effect for groups.
Items
An item is an element whose AccordionControlElement.Style property is set to Item. These elements serve two purposes.
Items can act as buttons. You can handle the AccordionControlElementBase.Click or AccordionControl.ElementClick event to respond to item clicking.
Items can display custom controls in an expandable area below an item header. To do this, provide a content container to the item using the AccordionControlElementBase.ContentContainer property or the AccordionControl.GetContentContainer event.
To add a content container to an item at design time, use the “Add ContentContainer” link in the item’s smart tag.
Tip
An accordion content container’s Padding property initially equals 0. Set it to -1 to force the container to use paddings according to the currently applied skin.
The added container can be vertically resized and customized at design time. You can drop custom controls onto the container.
By default, items are not drawn as selected when clicked. You can set the AccordionControl.AllowItemSelection property to true to change this behavior.
Search Panel
Accordion elements can be grouped into a complex multi-level hierarchy. Thus, to quickly find the required element, you can use the embedded search panel. A search panel is docked to the control’s top and displays a filter control. The figure below illustrates the default filter control.
Text entered to this filter control is used to find elements of both group and item types. Found items are displayed together with their parent groups. Appropriate groups in turn are displayed with their child elements. The figure below illustrates an example.
When the AccordionControl.ShowFilterControl property is set to Always, a built-in filter control is always visible. If the property is set to Auto, an end-user can display the built-in filter control by pressing the CTRL+F shortcut. The filter control is closed on pressing ESC.
You can also replace the built-in filter control with your own custom one. To do so, you need to assign an object of a class that implements the DevExpress.XtraBars.Navigation.IFilterContent interface to the AccordionControl.FilterControl property. To provide filtering capabilities in an external filter control, use SearchControl.