A newer version of this page is available. Switch to the current version.

How To: Create a PageGroup Container

  • 4 minutes to read

Prerequisites

  1. Create a Windows Forms Application.
  2. Windows UI applications are generally designed to run in full-screen mode. Modify the main form to meet these requirements. Set the FormBorderStyle property to None and the WindowState property to Maximized.
  3. Drop a DocumentManager component on the form.
  4. Change the DocumentManager's View to WindowsUI View. Click the DocumentManager's smart tag and select the Convert To WindowsUIView option.

    Metro Getting Started - Convert To Metro View

Creating Page Group

  1. Run the Document Manager Designer:

    DocumentManager - Designer Metro

  2. Select the designer's 'Elements' page, switch to its 'Documents' section and add 2 Documents by clicking a corresponding button.

    Metro Getting Started - Add Documents

    After the Documents are created, a TileContainer and two Tiles corresponding to these Documents are automatically generated. We do not need these objects and will remove them utilizing the following steps.

  3. Switch to the 'Tiles' page. Delete the automatically created Tiles by clicking the 'Delete Tile' button.

    Metro Getting Started - Automatic Tiles

  4. Finally, remove the automatically created TileContainer as well.

    Metro Getting Started - Automatic Container

  5. Create a PageGroup container. To do so, click the 'Add New Container' button and select 'PageGroup' from the drop-down menu.

    Metro Getting Started - Add Container

  6. Go to the designer's 'Navigation Tree' section. Here you can see the application's hierarchy. The topmost container is our PageGroup. It does not yet contain any documents (its inherited DocumentGroup.Items collection is empty). Add documents to the PageGroup by dragging them from the 'Documents' panel into the 'Items' node.

    Metro Getting Started - Add Documents to a Container

    The resulting navigation tree will look like following.

    Metro Getting Started - Navigation Tree

  7. The Documents created in step 6 are empty. In order to display content within these documents, we will use the Deferred Load feature. With this feature, contents for Documents will be provided via an event. Switch to the designer's 'Views' page and select the WindowsUIView object. In the property grid, switch to events and double-click the BaseView.QueryControl event.

    Metro Getting Started - QueryControl Event

    Type the following code in the BaseView.QueryControl event handler.

    
    private void windowsUIView1_QueryControl(object sender, DevExpress.XtraBars.Docking2010.Views.QueryControlEventArgs e) {
        WindowsUIView view = sender as WindowsUIView;
        if (e.Document == view.Documents[0]) {
            e.Control = new RichEditControl() { Text = "Text1" };
        }
        else e.Control = new RichEditControl() { Text = "Text2" };
    }
    

    As you noticed, RichEditControls are used as Documents' content. To compile and run the solution, ensure that all required assemblies are included in the solution.

  8. Run the application. The result is demonstrated in the figure below.

    Metro Getting Started - Result

Additional Settings

You can customize the PageGroup's advanced settings in the designer's 'Content Containers' page. For instance you can change the PageGroup's caption and animation effects that occur when switching between Documents. To do so, go to the mentioned designer's section and set the IDocumentSelectorDefaultProperties.SwitchDocumentAnimationMode property to the desired value. Additionally, you can specify the IDocumentSelectorDefaultProperties.SwitchDocumentAnimationFrameInterval and IDocumentSelectorDefaultProperties.SwitchDocumentAnimationFramesCount properties to set the desired animation quality and duration.

You can also set appearance options in the designer's 'Appearance' page.

Metro Getting Started - Appearances

Code

This section demonstrates how to create the example in code. Because of automatic Tiles and TileContainer generation (see step 6), we have to use the WindowsUIView.QueryStartupContentContainer to set an application start-up container.


private void windowsUIView1_QueryStartupContentContainer(object sender, DevExpress.XtraBars.Docking2010.Views.WindowsUI.QueryContentContainerEventArgs e) {
    WindowsUIView view = sender as WindowsUIView;
    //Creating documents
    DevExpress.XtraBars.Docking2010.Views.WindowsUI.Document doc1 = new DevExpress.XtraBars.Docking2010.Views.WindowsUI.Document() { Caption = "Document 1" };
    DevExpress.XtraBars.Docking2010.Views.WindowsUI.Document doc2 = new DevExpress.XtraBars.Docking2010.Views.WindowsUI.Document() { Caption = "Document 2" };
    view.Documents.AddRange(new DevExpress.XtraBars.Docking2010.Views.WindowsUI.Document[] { doc1, doc2 });
    //Creating and populating content container
    DevExpress.XtraBars.Docking2010.Views.WindowsUI.PageGroup pageGroup1 = new DevExpress.XtraBars.Docking2010.Views.WindowsUI.PageGroup();
    pageGroup1.Items.AddRange(new DevExpress.XtraBars.Docking2010.Views.WindowsUI.Document[] { doc1, doc2 });
    view.ContentContainers.Add(pageGroup1);
    //Additional settings
    pageGroup1.Caption = "Page Group";
    pageGroup1.Properties.SwitchDocumentAnimationMode = TransitionAnimation.VerticalSlide;
    view.AppearanceCaption.ForeColor = System.Drawing.Color.OrangeRed;
    //Setting a start-up container
    e.ContentContainer = pageGroup1;
}

private void windowsUIView1_QueryControl(object sender, DevExpress.XtraBars.Docking2010.Views.QueryControlEventArgs e) {
    WindowsUIView view = sender as WindowsUIView;
    if (e.Document == view.Documents[0]) {
        e.Control = new RichEditControl() { Text = "Text 1" };
    }
    else e.Control = new RichEditControl() { Text = "Text 2" };
}