Back to Devexpress

Get Started with Document Manager

windowsforms-402857-controls-and-libraries-application-ui-manager-get-started.md

latest8.7 KB
Original Source

Get Started with Document Manager

  • Jan 15, 2025
  • 6 minutes to read

This topic introduces major Document Manager concepts. We also recommend that you review these help articles that demonstrate how the Document Manager component can help you build different UI types:

Create a Sample Project

  • Create a blank Windows Forms project (you can use the “Blank Application” template from the Template Gallery) and drop a DocumentManager component on a form.

  • Document Manager includes multiple Views. The default View is “Tabbed”. Use the component smart tag menu to switch to another View.

  • Use the same smart tag menu to open the Designer dialog. Go to the Documents tab and click Add New Document.

  • Create another User Control, rebuild the solution, and go back to the “Documents” tab of the Document Manager Designer. Notice that the “Populate” button is now enabled - you can click it to add a new Document for every UserControl in your app. Created documents refer to their content by ControlName and ControlTypeName properties.

  • Another option to add and populate documents is to call View.AddDocument method overloads. You do not need to handle QueryControl for Documents added in this manner.

  • You now have three Documents docked as tabs. To move and select them, use View controller methods. You can access the View controller with the BaseView.Controller property.

Document Groups

Tabbed Documents are not hosted directly inside the View; they must be placed in DocumentGroup containers. All Documents you create are first placed into a default Group. When you or your users dock a Document to either side of another Document, the View creates new groups for these Documents. The figure below illustrates three side-by-side Documents. Each document resides in its own Group.

If you need to rearrange Documents in code, create Document Groups and use View.Controller.Dock method overloads to place Documents into these Groups.

csharp
DocumentGroup group2 = new DocumentGroup();
DocumentGroup group3 = new DocumentGroup();
tabbedView1.DocumentGroups.AddRange(new DocumentGroup[] { group2, group3 });
tabbedView1.Controller.Dock((Document)tabbedView1.Documents[1], group2);
tabbedView1.Controller.Dock((Document)tabbedView1.Documents[2], group3);
vb
Dim group2 As New DocumentGroup()
Dim group3 As New DocumentGroup()
tabbedView1.DocumentGroups.AddRange(New DocumentGroup() { group2, group3 })
tabbedView1.Controller.Dock(CType(tabbedView1.Documents(1), Document), group2)
tabbedView1.Controller.Dock(CType(tabbedView1.Documents(2), Document), group3)

The code above arranges all three documents side-by-side in a horizontal line. If you need to arrange groups in a column (one below another), change the View’s orientation.

csharp
tabbedView1.Orientation = Orientation.Vertical;
vb
tabbedView1.Orientation = Orientation.Vertical

With default View settings, all groups can be arranged either vertically (in a column) or horizontally (in a row). If you need to mix vertically and horizontally oriented groups and allow users to freely arrange Documents across the View surface, enable Free Layout Mode.

csharp
tabbedView1.EnableFreeLayoutMode = DevExpress.Utils.DefaultBoolean.True;

DocumentGroup group2 = new DocumentGroup();
DocumentGroup group3 = new DocumentGroup();
tabbedView1.DocumentGroups.AddRange(new DocumentGroup[] { group2, group3 });

group2.DockTo(tabbedView1.DocumentGroups[0], Orientation.Vertical);
group3.DockTo(group2, Orientation.Horizontal);

tabbedView1.Controller.Dock((Document)tabbedView1.Documents[1], group2);
tabbedView1.Controller.Dock((Document)tabbedView1.Documents[2], group3);
vb
tabbedView1.EnableFreeLayoutMode = DevExpress.Utils.DefaultBoolean.True

Dim group2 As New DocumentGroup()
Dim group3 As New DocumentGroup()
tabbedView1.DocumentGroups.AddRange(New DocumentGroup() { group2, group3 })

group2.DockTo(tabbedView1.DocumentGroups(0), Orientation.Vertical)
group3.DockTo(group2, Orientation.Horizontal)

tabbedView1.Controller.Dock(CType(tabbedView1.Documents(1), Document), group2)
tabbedView1.Controller.Dock(CType(tabbedView1.Documents(2), Document), group3)

Customize Document Properties

Use properties from the TabbedView.DocumentProperties section to specify additional document settings. For example, you can disable the AllowClose property to remove a close button from document headers.

All Boolean properties from the DocumentProperties group are also available for individual documents. Individual document properties are of the DefaultBoolean type: the DefaultBoolean.Default value means this document should act according to the global View setting, and DefaultBoolean.True/DefaultBoolean.False values override it.

csharp
//only document2 can float
tabbedView1.DocumentProperties.AllowFloat = false;
document2.Properties.AllowFloat = DevExpress.Utils.DefaultBoolean.True;
vb
'only document2 can float
tabbedView1.DocumentProperties.AllowFloat = False
document2.Properties.AllowFloat = DevExpress.Utils.DefaultBoolean.True

Floating Document Host

You can allow floating Documents to be placed into containers that contain their own document manager components. Such containers can host multiple documents, which allow you and your users to group floating documents rather than keep each of them as a separate window.

To enable this behavior, set the FloatingDocumentContainer property to DocumentsHost.

csharp
tabbedView1.FloatingDocumentContainer = FloatingDocumentContainer.DocumentsHost;
vb
tabbedView1.FloatingDocumentContainer = FloatingDocumentContainer.DocumentsHost

Document Manager in MVVM Applications

DevExpress MVVM Framework allows you to build applications that follow a Model-View-ViewModel concept. This concept implies that data, UI, and application logic are split into independent layers.

To manage a Document UI from a ViewModel layer, register a DocumentManagerService or a WindowedDocumentManagerService in the View layer, and call its public methods from a ViewModel to create, dock and select documents.

csharp
//View
mvvmContext1.RegisterService(DocumentManagerService.Create(tabbedView1));

//ViewModel
public void ShowDocument(){
    var dms = this.GetService<IDocumentManagerService>();
    var doc = dms.CreateDocument(...);
    doc.Show();
}
vb
'View
mvvmContext1.RegisterService(DocumentManagerService.Create(tabbedView1))

'ViewModel
Public Sub ShowDocument()
    Dim dms = Me.GetService(Of IDocumentManagerService)()
    Dim doc = dms.CreateDocument(...)
    doc.Show()
End Sub

See this help article for details: Standard DevExpress Services.