Why can't DockableContents be closed?

Aug 9, 2009 at 5:56 AM
Edited Aug 9, 2009 at 6:01 PM

I searched what little information I could find, including these forums, but could find no rationale for not being able to close DockableContent windows. DocumentContent is closable but doesn't have the behavior I want. I want to be able to (easily) close dockable windows that the user opened but there doesn't seem to be any clean way to do it.

What's the thinking behind this? Why aren't DockableContent windows thought of like windows that can be opened and closed by the application (or the user)?

Aug 9, 2009 at 10:05 AM

I don't know exactly what you want, but in the projects demo are many DockableContents (Properties, Server Explorer, ...) and you can close each of them by clicking on the "X".

And in the "Home" document you can do this by code.

Aug 9, 2009 at 6:11 PM

Clicking the X on a DockableContent doesn't appear to actually close anything, it just hides it.

I need the window to actually close and release its resources and data.

It appears that I might be able to track the items I add to the DockablePane and remove them from the Items collection at a later time, but there doesn't appear to be any way for me to detect that the X has been pressed or the window closed, at least not without writing some really ugly code that it makes no sense I should have to write.

Sadly, this is kind of a deal breaker for me so it's not clear I can actually use this otherwise pretty nice package. If not, it's obviously irrelevant *why* this design choice was made but I still have a slight intellectual curiosity as to the rationale behind such a decision. I can't think of any reasonable scenario where a user would expect clicking on an X is not clearly a closing gesture, as opposed to simply a hiding gesture.

Even in Visual Studio, which I presume to be the design motivation for this package, as a user, I assume that clicking the X on a docked window closes that window and releases the resources that window consumes.

Anyway, it's obviously of minor importance. I was just wondering if there was an explanation...some consideration I overlooked in how a dockable window package would have to be designed.

Aug 10, 2009 at 8:29 AM

In my actual project I'm glad about that. I have some DockableContant's with different contents.
When you close that DockableContent, all the position informations are away, so you have to remember them for yourself
to reopen it at the same position.
When you want to close this, just remove your content. I think that's enough.

In my app I have some documents, that uses the DockableContants (Settings-Window, Output-Window, ...). When I close a document I
remove the contant from that DockableContant.

I think that's not the scenario you need. What you need is more a property "HideOnClose" for the DockableContant to set it to false to close it really.

I don't know if Ado can do this because of the internal structure. I think he will read this and give an answer.

Best regards,


Aug 10, 2009 at 9:47 AM

Hi again,
I changed two parts to get it work.

First you have to add a property in DockableContent like this:

#region HideOnClose
public static DependencyProperty HideOnCloseKey = DependencyProperty.Register("HideOnClose", typeof(bool), typeof(DockableContent), new PropertyMetadata(true));

public bool HideOnClose
    get { return (bool)GetValue(HideOnCloseKey); }
    set { SetValue(HideOnCloseKey, value); }

After that change the Close() method in DockablePane:

internal virtual void Close()
    if (SelectedItem is DockableContent)
        DockableContent item = SelectedItem as DockableContent;
        if (item.HideOnClose)
            GetManager().Hide(SelectedItem as DockableContent);
            this.Items.Remove(SelectedItem as DockableContent);

Please check if it works for you. The only missing is to get some close-events after that,
but that should be no problem.
Maybe there should be some checkups in the close method, but try it first.

Best regards,