Posted 14 years ago
by Nate Smith
-
Software Engineer,
Logical Progression Group

I am using a TabbedMdiHost inside a DockSite to host some designer windows. Here's a stripped down look at the XAML.
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.
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.
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!
<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">
DocumentWindow documentWindow = new DocumentWindow(DocumentsContainer.DockSite, "FormDocumentWindow", _formName, bitmap, designerPanel);
((DocumentWindow)e.Window).Destroy();
The DockSite is null and is read-only so I'm stuck. Am I missing something here?
Thanks in advance!