Skip to main content

Bar and Ribbon Merging

  • 9 minutes to read

The Document Manager component supports the merging of RibbonControl and BarManager controls. When this feature is enabled, Bar Item Links contained within Documents are merged to corresponding Bars and Ribbon Page Groups within the parent form. You can find more info about Bar and Ribbon merging mechanics in the MDI Merging and Ribbon Merging topics.

In this topic, you will learn how to merge BarManager components within a Document Manager.

  1. Start Visual Studio and create a new Windows Forms Application project. Enter the project’s name, choose the solution folder, and click OK.

    Document Manager - BarMerging - Create Project

  2. Find the Document Manager component in the toolbox and drop it onto the form. By default, the Document Manager applies the Tabbed View to display its Documents. You can change the current Document Manager View by clicking the Convert to… links within the Tasks menu, which is invoked by clicking the component’s smart tag (see the figure below). For this example, you will use the Tabbed View, so leave the Convert to… settings unchanged and invoke the Document Manager designer by clicking the Run Designer link.

    Document Manager - BarMerging - Designer

  3. Switch to the Documents section in the Main tab. Click Add New Document to create the required number of tabbed Documents.

    Document Manager - BarMerging - Add Documents

  4. The Documents created in the previous step are empty. If you try to launch the app now, you will get the ‘Deferred Loading Exception’, which asks you to set the Document content. In this example, you will use a UserControl for the content. Right-click the project in the Visual Studio Solution Explorer window and select Add | New Item.

    Document Manager - BarMerging - Add UserControl 1

    In the invoked dialog, choose the User Control option, enter its name and click Add, to add it into the project. Rebuild your project and make sure no errors are present.

    Document Manager - BarMerging - Add UserControl 2

    Now you can set the User Control as the content for your Documents. To do so, handle the BaseView.QueryControl event. Refer to the Deferred Load topic for details.

    private void tabbedView1_QueryControl(object sender, DevExpress.XtraBars.Docking2010.Views.QueryControlEventArgs e) {
        e.Control = new ucContent();
  5. Drop the BarManager and RichEditControl components onto the User Control. Once dropped, the Bar Manager creates three child Bar objects - Main Menu, Status Bar and a regular Toolbar. We will not need the Main Menu bar, so select it and press the Delete key to remove it. To add items to the Toolbar and Status Bar, click the [Add] label within the required Bar and select the desired item type. Next, add two BarButtonItem objects to the Toolbar (Undo and Redo) and a BarStaticItem object to the Status Bar. The figure below displays the approximate result.

    Document Manager - BarMerging - UserControl

    To specify BarButtonItem actions, handle their BarItem.ItemClick events. Use the built-in RichEditControl’s RichEditControl.Undo and RichEditControl.Redo methods.

    private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {
    private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) {

    Finally, set the BarItem.Enabled property of the Undo and Redo buttons to false.

    barButtonItem1.Enabled = barButtonItem2.Enabled = false;

    These buttons will be enabled only after an end-user has modified text within the RichEditControl. To implement this behavior, handle the RichEditControl’s TextChanged event.

    private void richEditControl1_TextChanged(object sender, EventArgs e) {
        if (true == (sender as RichEditControl).CanUndo) barButtonItem1.Enabled = true;
            else barButtonItem1.Enabled = false;
        if (true == (sender as RichEditControl).CanRedo) barButtonItem2.Enabled = true;
            else barButtonItem2.Enabled = false;
  6. Now add the Bar Manager for the main application form and customize its bars. Refer to the previous step if you have any difficulties. The figure below illustrates the main application form with a customized Bar Manager.

    Document Manager - BarMerging - MainForm

  7. Finally, merge Bar Manager from the UserControl with the main form’s BarManager. First, set the DocumentManager.RibbonAndBarsMergeStyle property to Always.

    documentManager1.RibbonAndBarsMergeStyle = DevExpress.XtraBars.Docking2010.Views.RibbonAndBarsMergeStyle.Always

    Main Menus are merged automatically. All other Bar types - Status Bars and Toolbars - need to be merged manually. To do so, handle the BarManager.Merge and BarManager.UnMerge events of the main form’s BarManager.

    private void barManager1_Merge(object sender, DevExpress.XtraBars.BarManagerMergeEventArgs e) {
        (sender as BarManager).StatusBar.Merge(e.ChildManager.StatusBar);
    private void barManager1_UnMerge(object sender, DevExpress.XtraBars.BarManagerMergeEventArgs e) {
        (sender as BarManager).StatusBar.UnMerge();

    The image below illustrates the result. The Undo and Redo buttons are merged to the main form’s Toolbar, and the ‘Page 1’ static item is merged to the main form’s Status Bar. This behavior persists when you float a Document or move it to another DocumentGroup.

    Document Manager - BarMerging - Result


In this sample, you can also see another Document Manager feature - Microsoft Visual Studio-like behavior. When you click BarItemLinks within the main form’s RibbonControl, child Documents do not loose their focus. In this example, the feature allows the ‘Undo’ and ‘Redo’ buttons to perform required operations exactly on the currently focused RichEditControl.

Complete Code

View Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DocumentManagerBarMerging {
    static class Program {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main() {
            Application.Run(new Form1());