DockSite goes null when last child is Destroy()'ed

Docking/MDI for WPF Forum

Posted 8 years ago by Nate Smith - Software Engineer, Logical Progression Group
Avatar
I am using a TabbedMdiHost inside a DockSite to host some designer windows. Here's a stripped down look at the XAML.


<docking:DockSite x:Name="dockingSiteMain">
    <docking:Workspace>
        <docking:SplitContainer>
            <docking:TabbedMdiHost Name="DocumentsHost">
                <docking:TabbedMdiContainer Name="DocumentsContainer">
                </docking:TabbedMdiContainer>
            </docking:TabbedMdiHost>
        </docking:Workspace>
    </docking:SplitContainer>
</docking:DockSite x:Name="dockingSiteMain">

For various reasons I have AreDocumentWindowsDestroyedOnClose set to False. So when the user creates a new document, I programatically create a DocumentWindow passing the DockSite of the DocumentsContainer to the constructor.

DocumentWindow documentWindow = new DocumentWindow(DocumentsContainer.DockSite, "FormDocumentWindow", _formName, bitmap, designerPanel);
Everything was great until I realized I was never calling Destroy() on the DocumentWindows as they were closed and I was getting memory leaks. So I started listening for the WindowClosing event on the main DockingSite and called Destroy() on the DocumentWindow that was closing.

((DocumentWindow)e.Window).Destroy();
If I open lots of documents and close them, everything is fine. However, once I close the last Document window, the DockSite property of my DocumentsContainer goes null. So suddenly when I want to add a new DocumentWindow as pass it the DockSite, it is now null and I get an exception when I call Activate() on the new DocumentWindow: "This operation is invalid since the DockingWindow has not yet been registered with a DockSite."

The DockSite is null and is read-only so I'm stuck. Am I missing something here?

Thanks in advance!

Comments (1)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nate,

You should never give TabbedMdiContainer, ToolWindowContainer, or SplitContainer names in your XAML (i.e. x:Name). These types are created and destroyed as docking windows are opened, closed, or moved.

So in your case, the DocumentsContainer is being removed since it is no longer needed. Since the DocumentsContainer was destroyed, it's DockSite property will be null.

In your code, you can simply pass "this.dockingSiteMain" instead of "DocumentsContainer.DockSite", since the latter refers to the former (when it is valid).


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.