A newer version of this page is available. Switch to the current version.

BaseView.CustomDocumentsHostWindow Event

Fired before a host container for floating documents is created, allowing you to create your own custom floating document container.

Namespace: DevExpress.XtraBars.Docking2010.Views

Assembly: DevExpress.XtraBars.v19.2.dll

Declaration

public event CustomDocumentsHostWindowEventHandler CustomDocumentsHostWindow

Event Data

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

Remarks

Floating DocumentManager's documents can be hosted either separately (each one in its own container) or in a specific documents host, where other floating documents can be docked. The way floating documents are hosted is specified via the BaseView.FloatingDocumentContainer property. In DocumentsHost mode, documents are displayed within a container that has its own DocumentManager component. Thus, all events related to floating documents are fired for this local DocumentManager rather than for the main DocumentManager component. If you need to handle these events, use the CustomDocumentsHostWindow property.

NOTE

Follow this link to download the complete sample.

First, add a new class to your solution by clicking the 'Add' -> 'New Item' pop-up menu item in Visual Studio's Solution Explorer or pressing the Ctrl+Shift+A shortcut. Inherit this class from the Form class and implement the IDocumentHostWindows interface for it.

using DevExpress.XtraBars.Docking2010;

namespace myApp {
    class customDocHost : Form, IDocumentsHostWindow {

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

        public DocumentManager DocumentManager {
            get { throw new NotImplementedException(); }
        }
    }
}

Within your new class constructor, add your own DocumentManager component and subscribe to required events. In this example, the BaseView.DocumentClosing event is handled.

using DevExpress.XtraBars.Docking2010;

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

        public customDocHost() {
            floatDocHost = new DocumentManager();
            floatDocHost.ContainerControl = this;
            floatDocHost.View.DocumentClosing += View_DocumentClosing;
            floatDocHost.View.FloatingDocumentContainer = DevExpress.XtraBars.Docking2010.Views.FloatingDocumentContainer.DocumentsHost;
        }

        void View_DocumentClosing(object sender, DevExpress.XtraBars.Docking2010.Views.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);
        }
    }
}

Finally, subscribe to the main DocumentManager's CustomDocumentsHostWindow event and set your custom document host as a floating document container.

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

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

        private customDocHost CreateCustomHost() {
            return new customDocHost();
        }
    }
}

Since float containers are not a permanent storage for documents and your end-users can undock documents from a custom container and make them float, new float document containers can appear again and again. These new containers will be the default, not our custom containers, and so document events will be again be unreachable. To overcome this issue, handle the CustomDocumentsHostWindow event for your custom container and return this container as its own custom document container. When it is done, undocking a Document from a custom container will create another custom container, which already handles required events.

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

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