Skip to main content
A newer version of this page is available. .

DockControllerBase.AddDocumentPanel(DocumentGroup, Uri) Method

Adds a new DocumentPanel to the specified DocumentGroup and loads the contents of a Window, Page or UserControl defined in the specified XAML into the DocumentPanel.

Namespace: DevExpress.Xpf.Docking

Assembly: DevExpress.Xpf.Docking.v19.1.dll

Declaration

public DocumentPanel AddDocumentPanel(
    DocumentGroup group,
    Uri uri
)

Parameters

Name Type Description
group DocumentGroup

A DocumentGroup object to which a new DocumentPanel is added.

uri Uri

The uniform resource identifier (URI) of the XAML that defines a Window, Page or UserControl to be loaded into the created DocumentPanel.

Returns

Type Description
DocumentPanel

The created DocumentPanel object.

Remarks

When the URI refers to a Window or Page, the AddDocumentPanel method loads the contents of the specified Window/Page. The Window/Page objects themselves, and their resources and event handlers are not loaded, and they will not be available via the inherited LayoutPanel.Control property.

When the URI refers to a UserControl, the UserControl itself is loaded. You can access the loaded UserControl via the inherited LayoutPanel.Control property.

Note

Loading the XAML file is delegated to the Application.LoadComponent method.

Example

The following code adds a new DocumentPanel object to a DocumentGroup, and loads the content of the “ChildPage.xaml” into this panel:

DocumentPanel panel = dockLayoutManager1.DockController.AddDocumentPanel(
    documentGroup1, new Uri(@"Layouts\ChildPage.xaml", UriKind.Relative));
panel.Caption = "Page 1";

Example

You can define a Window, Page or UserControl in external XAML files and then, with DXDocking, load their contents into DocumentPanel objects. This example demonstrates how to load an external Window and UserControl into DocumentPanels. In the example three approaches are demonstrated:

  1. The contents of MyWindow.xaml is loaded into a DocumentPanel at design time (in XAML) via the DocumentPanel.Content property. The Content property accepts a Uri object, which must refer to a XAML file defining a Window, Page or UserControl.

    <dxdo:DocumentPanel 
      x:Name="docPanel2" 
      Caption="Panel 2" 
      Content="{dxdo:RelativeUri UriString=CustomWindows\\MyWindow.xaml}"/>
    
  2. The DocumentPanel.Content property is set to a Uri object at runtime:

    docPanel1.Content = new Uri(\@"CustomWindows\MyWindow1.xaml", UriKind.Relative);
    
  3. The DockController.AddDocumentPanel method creates a new DocumentPanel object and loads the contents of an external XAML file into the created panel.

panel1 = dockLayoutManager1.DockController.AddDocumentPanel(
    documentGroup1,
    new Uri(\@"CustomWindows\UserControl1.xaml", 
    UriKind.Relative)
);
panel1.Caption = "Document " + (ctr++).ToString();

In the example, the XAML file defines a UserControl object. The loaded UserControl is accessed via the DocumentPanel‘s Control property and then a method on the UserControl is invoked.

//...

(panel1.Control as UserControl1).SetDataContext(imageInfo);

You can see this in action by clicking the “Set DataContext for UserControl” button in the example.

Imports Microsoft.VisualBasic
Imports System
Imports System.Windows
Imports System.Windows.Media.Imaging
Imports DevExpress.Xpf.Docking

Namespace DocumentPanel_Content
    Partial Public Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub ActivateItem(ByVal item As BaseLayoutItem)
            dockLayoutManager1.LayoutController.Activate(item)
        End Sub

        'Load MyWindow1.xaml into docPanel1
        Private Sub btnSetContent_ItemClick(ByVal sender As Object, ByVal e As DevExpress.Xpf.Bars.ItemClickEventArgs)
            ActivateItem(docPanel1)
            docPanel1.Content = New Uri("CustomWindows\MyWindow1.xaml", UriKind.Relative)
        End Sub

        Private panel1 As DocumentPanel = Nothing
        Private ctr As Integer = 1

        Private Sub btnAddDockPanel_ItemClick(ByVal sender As Object, ByVal e As DevExpress.Xpf.Bars.ItemClickEventArgs)
            panel1 = dockLayoutManager1.DockController.AddDocumentPanel(documentGroup1, New Uri("CustomWindows\UserControl1.xaml", UriKind.Relative))
            panel1.Caption = "Document " & (ctr).ToString()
            ctr += 1

            DocumentPanel.SetMDISize(panel1, New Size(400, 300))
            DocumentPanel.SetMDILocation(panel1, New Point(200, 200))
            ActivateItem(panel1)
        End Sub
        Private Sub btnSetDataContext_ItemClick(ByVal sender As Object, ByVal e As DevExpress.Xpf.Bars.ItemClickEventArgs)
            If panel1 Is Nothing Then
                Return
            End If
            Dim uri As New Uri("/Images/IMG_1391.jpg", UriKind.Relative)
            Dim imageInfo As New ImageInfo()
            imageInfo.Source = New BitmapImage(uri)
            imageInfo.Description = uri.ToString()
            'Invoke a method on the loaded UserControl
            TryCast(panel1.Control, UserControl1).SetDataContext(imageInfo)

            ActivateItem(panel1)
        End Sub
    End Class
End Namespace
See Also