Tabbed MDI Container Problem After Closing All Windows

Docking/MDI for WPF Forum

Posted 11 years ago by Ben McIntosh
Version: 10.1.0523
Avatar

Hello,

Granted I have an older verion of the docking control, but I hope you can help me.  This used to work, but I guess the latest build for my purchase must have changed.

I start with some tabbed windows open in a tabbed MDI container in XAML.  I then create a handle to that container in order to be able to add windows to it and iterate through the open windows.  If I wanted to close all tabs, then add one, I would do something like:

myMDIContainer.Close();
myMDIContainer.Items.Add(new DocumentWindow());

Again, this used to work fine, but now as soon as I call the Close() method, suddenly the Workspace and Docksite properties of the Container are null, and the new windows don't show up when adding them to the container.  Is there a way to re-add this container back to the docksite?  If not, then how would I add new windows after closing them all?

Thanks,

Ben

Comments (4)

Answer - Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Ben,

You should never reference container instances or work with them directly.  That will not work properly since containers get dynamically created and destroyed as the layout changes.  I'm surprised you didn't have the same issues before since it's always been that way.

Instead you want to call the methods on DocumentWindow like Activate().  That will put the document window in the active MDI container and everything will work properly.


Actipro Software Support

Posted 11 years ago by Ben McIntosh
Avatar

Ah that makes sense, thank you.  But, there are so many good properties and methods on the MDIContainer.  What would be the recommended way to (1) get a list of all currently open documents in a particular MDI Host, and (2) close all currently open documents in a particular MDI Host?

Previously, I could accomplish (1) by simply viewing the MDI Container "Windows" property and (2) by simply calling the MDI Container's close() method.  Do you recommend manually keeping a parallel list of open documents in code and closing them one-by-one, or get the document's parent container and call the close() method?

Thanks again for you help.

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Ben,

Nearly everything can be done off of DockSite.  For instance the DockSite.Documents collection has all open document windows.  You could enumerate those to an array and cycle through it to close each DocumentWindow there.

If you mean you only want to close document windows in a particular container (not all document windows), you could probably still use the container's Close method.  But don't store a ref to that container.  Get one of the DocumentWindows that you are looking to close, and look at that object's ParentContainer property to get the container.  By doing it dynamically at run-time you won't run into the destroyed containers issue.


Actipro Software Support

Posted 11 years ago by Ben McIntosh
Avatar

Perfect, thanks for the very helpful answer!

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.