Skip to main content

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.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

public event CustomDocumentsHostWindowEventHandler CustomDocumentsHostWindow

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.
using DevExpress.XtraBars.Docking2010;

namespace myApp {
    class customDocHost : Form, IDocumentsHostWindow {

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

        public DocumentManager DocumentManager {
            get { throw new NotImplementedException(); }
        }
    }
}
  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.
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);
        }
    }
}
  1. Handle the main DocumentManager CustomDocumentsHostWindow event and replace the default floating document container with your custom class instance.
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();
        }
    }
}
  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.

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

void View_CustomDocumentsHostWindow(object sender, CustomDocumentsHostWindowEventArgs e) {
    e.Constructor = () => new customDocHost();
}
See Also