Back to Devexpress

BaseView.CustomDocumentsHostWindow Event

windowsforms-devexpress-dot-xtrabars-dot-docking2010-dot-views-dot-baseview-f9163fe2.md

latest8.6 KB
Original Source

BaseView.CustomDocumentsHostWindow Event

Allows you to replace the default container for floating documents. Handle this event only when the BaseView.FloatingDocumentContainer property equals DocumentsHost.

Namespace : DevExpress.XtraBars.Docking2010.Views

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public event CustomDocumentsHostWindowEventHandler CustomDocumentsHostWindow
vb
Public Event CustomDocumentsHostWindow As CustomDocumentsHostWindowEventHandler

Event Data

The CustomDocumentsHostWindow event's data class is DevExpress.XtraBars.Docking2010.CustomDocumentsHostWindowEventArgs.

Remarks

If the FloatingDocumentContainer property equals DocumentsHost, each floating document is hosted inside a container that accepts other documents. At runtime, users can dock one floating document to another.

In this setup, floating documents are managed by Document Managers inside document containers - rather than by their source Document Manager. If you need to handle events related to floating documents, create a custom container with a Document Manager that handles all required events.

  1. Right-click your project in Visual Studio Solution Explorer, and click “Add | New Item”. Add a new class that inherits from Form and implements the IDocumentHostWindows interface.
csharp
using DevExpress.XtraBars.Docking2010;

namespace myApp {
class customDocHost : Form, IDocumentsHostWindow {

public bool DestroyOnRemovingChildren {
get { throw new NotImplementedException(); }
}

public DocumentManager DocumentManager {
get { throw new NotImplementedException(); }
}
}
}
vb
Imports DevExpress.XtraBars.Docking2010

Namespace myApp
Class customDocHost
Inherits Form
Implements IDocumentsHostWindow

Public ReadOnly Property DestroyOnRemovingChildren() As Boolean
Get
Throw New NotImplementedException()
End Get
End Property

Public ReadOnly Property DocumentManager() As DocumentManager
Get
Throw New NotImplementedException()
End Get
End Property
End Class
End Namespace
  1. Add a Document Manager component to your custom container, and subscribe to required events. In this sample, a Document Manager that operates floating documents handles the BaseView.DocumentClosing event.
csharp
using DevExpress.XtraBars.Docking2010;
using DevExpress.XtraBars.Docking2010.Views;

namespace myApp {
class customDocHost : Form, IDocumentsHostWindow {
DocumentManager floatDocHost;

public customDocHost() {
floatDocHost = new DocumentManager();
floatDocHost.ContainerControl = this;
//replace the previous code line with the following if main
//Document Manager uses the MdiParent property
//floatDocHost.MdiParent = this;
floatDocHost.View.DocumentClosing += View_DocumentClosing;
floatDocHost.View.FloatingDocumentContainer = FloatingDocumentContainer.DocumentsHost;
}

void View_DocumentClosing(object sender, DocumentCancelEventArgs e) {
//do something
}

public bool DestroyOnRemovingChildren {
get { return true; }
}

public DocumentManager DocumentManager {
get { return floatDocHost; }
}

protected override void Dispose(bool disposing) {
if (disposing)
floatDocHost.Dispose();
base.Dispose(disposing);
}
}
}
vb
Imports DevExpress.XtraBars.Docking2010
Imports DevExpress.XtraBars.Docking2010.Views

Namespace myApp
Friend Class customDocHost
Inherits Form
Implements IDocumentsHostWindow

Private floatDocHost As DocumentManager

Public Sub New()
floatDocHost = New DocumentManager()
floatDocHost.ContainerControl = Me
'replace the previous code line with the following if main
'Document Manager uses the MdiParent property
'floatDocHost.MdiParent = Me
AddHandler floatDocHost.View.DocumentClosing, AddressOf View_DocumentClosing
floatDocHost.View.FloatingDocumentContainer = FloatingDocumentContainer.DocumentsHost
End Sub

Private Sub View_DocumentClosing(ByVal sender As Object, ByVal e As DocumentCancelEventArgs)
'do something
End Sub

Public ReadOnly Property DestroyOnRemovingChildren() As Boolean
Get
Return True
End Get
End Property

Public ReadOnly Property DocumentManager() As DocumentManager
Get
Return floatDocHost
End Get
End Property

Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
floatDocHost.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
End Class
End Namespace
  1. Handle the main DocumentManager CustomDocumentsHostWindow event and replace the default floating document container with your custom class instance.
csharp
using DevExpress.XtraBars.Docking2010;
using DevExpress.XtraBars.Docking2010.Views;

namespace myApp {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
documentManager1.View.CustomDocumentsHostWindow += View_CustomDocumentsHostWindow;
documentManager1.View.FloatingDocumentContainer =
FloatingDocumentContainer.DocumentsHost;
}

void View_CustomDocumentsHostWindow(object sender, CustomDocumentsHostWindowEventArgs e) {
e.Constructor = new DocumentsHostWindowConstructor(CreateCustomHost);
}

private customDocHost CreateCustomHost() {
return new customDocHost();
}
}
}
vb
Imports DevExpress.XtraBars.Docking2010
Imports DevExpress.XtraBars.Docking2010.Views

Namespace myApp
Partial Public Class Form1
Inherits Form

Public Sub New()
InitializeComponent()
AddHandler documentManager1.View.CustomDocumentsHostWindow, AddressOf View_CustomDocumentsHostWindow
documentManager1.View.FloatingDocumentContainer = 
FloatingDocumentContainer.DocumentsHost
End Sub

Private Sub View_CustomDocumentsHostWindow(ByVal sender As Object, ByVal e As CustomDocumentsHostWindowEventArgs)
e.Constructor = New DocumentsHostWindowConstructor(AddressOf CreateCustomHost)
End Sub

Private Function CreateCustomHost() As customDocHost
Return New customDocHost()
End Function
End Class
End Namespace
  1. All documents undocked from the main Document Manager are now inside custom containers with their own Document Managers. However, FloatingDocumentContainer properties of these custom Document Managers are also equal to DocumentsHost (see step #2). If a user undocks a document from a custom container, this document will be placed into another default container. To fix this, ensure that instances of your class are custom containers of other custom containers.

Repeat step #3 for the custom container class.

csharp
public customDocHost() {
. . .
floatDocHost.View.CustomDocumentsHostWindow += View_CustomDocumentsHostWindow;
}

void View_CustomDocumentsHostWindow(object sender, CustomDocumentsHostWindowEventArgs e) {
e.Constructor = () => new customDocHost();
}
vb
Public Sub customDocHost()
AddHandler ...floatDocHost.View.CustomDocumentsHostWindow, AddressOf View_CustomDocumentsHostWindow
End Sub

Private Sub View_CustomDocumentsHostWindow(ByVal sender As Object, ByVal e As CustomDocumentsHostWindowEventArgs)
e.Constructor = Function() New customDocHost()
End Sub

See Also

FloatingDocumentContainer

RegisterDocumentsHostWindow

BaseView Class

BaseView Members

DevExpress.XtraBars.Docking2010.Views Namespace