How To: Populate the Widget View in Code

  • 3 minutes to read

This example demonstrates how to create and customize the WidgetView at runtime. In this example, the WidgetView contains two StackGroups, which host three Documents. Each Document displays different content in its normal and maximized states. StackGroups have relative lengths (their Length.UnitType properties are set to Star), which allows them to dynamically resize whenever the parent form resizes.

NOTE

1. When creating the Widget View-based application at runtime, do not specify the DocumentManager.MdiParent property manually. Otherwise, widgets will not be displayed.

2. Be sure to set the DocumentManager.ContainerControl property after the View is created and assigned to the DocumentManager.View property.

//ucPreview.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WidgetViewExample {
    public partial class ucPreview : UserControl {
        public ucPreview() {
            InitializeComponent();
        }
    }
}

//ucMaximizedContent.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WidgetViewExample {
    public partial class ucMaximizedContent : UserControl {
        public ucMaximizedContent() {
            InitializeComponent();
        }
    }
}

//Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraBars.Docking2010;
using DevExpress.XtraBars.Docking2010.Views.Widget;
using DevExpress.XtraEditors;

namespace WidgetViewExample {
    public partial class Form1 : XtraForm {
        public Form1() {
            InitializeComponent();
        }
        void Form1_Load(object sender, EventArgs e) {
            AddDocumentManager();
            for (int i = 0; i < 3; i++) {
                AddDocuments();
            }
            //Adding Documents to group1 is not necessary, since all newly created Documents are automatically placed in the first StackGroup.
            group1.Items.AddRange(new Document[] { view.Documents[0] as Document, view.Documents[1] as Document });
            view.Controller.Dock(view.Documents[2] as Document, group2);
        }

        WidgetView view;
        StackGroup group1, group2;
        void AddDocumentManager() {
            DocumentManager dM = new DocumentManager(components);
            view = new WidgetView();
            dM.View = view;
            view.AllowDocumentStateChangeAnimation = DevExpress.Utils.DefaultBoolean.True;
            group1 = new StackGroup();
            group2 = new StackGroup();
            group1.Length.UnitType = LengthUnitType.Star;
            group1.Length.UnitValue = 2;
            view.StackGroups.AddRange(new StackGroup[] { group1, group2 });
            dM.ContainerControl = this;
        }

        int count = 1;
        void AddDocuments() {
            Document document = view.AddDocument(new ucPreview()) as Document;
            document.MaximizedControl = new ucMaximizedContent();
            count++;
        }
    }
}