How to close the content of a DocumentWindow from its code behind file

Docking/MDI for WPF Forum

Posted 10 years ago by Pam Mao
Version: 10.2.0600

Hi, I hope the question can be answered:


I have a DocumentWindow named tw. I then have tw.Content set to some Windows UserControl with custom grid for the users to use. I then call the activate function of tw. The end result is that the screen/usercontrol properly docks onto the window.

However, I want to add logic in the usercontrol to perform certan checks before actually displaying the screen. If the conditions arent met, then i would like to exit/close/destroy the screen/usercontrol. I cant seem to find a way to do that in the C# code because when I try to find its parent of the usercontrol, I get null.


The closing/removing/unloading of the usercontrol must be done within the usercontrol itself.


Any help is appreciated!

Comments (1)

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


Since you manually set tw.Content, and you said you need a reference to the tool window, you could always set some custom property on the UserControl that would say which tool window owns it.  Then use that as needed.

The tool window containers use a ContentPresenter to show the selected tool window's content.  So you probably wouldn't be able to crawl up the visual tree to get the tool window.  Thus, what I suggested above is probably your best option.

Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.