[Version 1.3] DockablePane - Pane deletes and removes from layout when all children are removed

Jul 23, 2010 at 7:23 PM

This is the first time, I've ever looked far enough into the source to figure out what was going on, but basically the scenario is as follows.

 

I had a DocumentPane and after I removed all the children, it stays there in case I want to add new DocumentContents to it.

I also had an invisible DockablePane off to the side in the and I dynamically load pieces to it. So the first time, I load a DockableContent into it, the content and pane are where I want it to be. However, if only one item is in the pane and I close the content, it removes the entire DockablePane as well. So when I attempt to load my other DockablePane's, they just don't show up until I re-add the pane to the dockingmanager. However in doing so, I have to rebalance the tree to make sure it is set back as my original template.

 

So I tweaked the source and I'm not entirely certain how to submit patches or what not. Or perhaps someone has the "Correct" way to do what I was attempting to do.

but I did this in DockablePane.cs

I added a property

Snippet

        public bool CloseOnRemoveWithNoChildren
        {
            get { return (bool)GetValue(CloseOnRemoveWithNoChildrenProperty); }
            set { SetValue(CloseOnRemoveWithNoChildrenProperty, value); }
        }

        // Using a DependencyProperty as the backing store for PersistWithNoChildren.  This enables the pane to stay loaded even if no children remain
        public static readonly DependencyProperty CloseOnRemoveWithNoChildrenProperty =
            DependencyProperty.Register("CloseOnRemoveWithNoChildren"typeof(bool), typeof(DockablePane), new UIPropertyMetadata(true));


...

and I modified the following function

Snippet
		internal override ManagedContent RemoveContent(int index)
{
ManagedContent content = base.RemoveContent(index);
DockableContent dockableContent = content as DockableContent;

if (((dockableContent == null)
|| (dockableContent != null && dockableContent.SavedStateAndPosition == null)
|| (dockableContent != null && dockableContent.SavedStateAndPosition.ContainerPane != this)) 
                && Items.Count == 0
                && CloseOnRemoveWithNoChildren)
{
ResizingPanel containerPanel = Parent as ResizingPanel;
if (containerPanel != null)
containerPanel.RemoveChild(this);
}

return content;
}

Life is now good
Aug 17, 2010 at 3:47 PM
Thanks for the snippet, it is also required if you add a Prism region to DockablePane to prevent the region to be destroyed when the last view has been removed.
Aug 17, 2010 at 3:58 PM

No problem. My question is how do I get these changes in the next revision? Is there an appropriate patch submission that someone can review and make sure it goes in for future releases?

Aug 17, 2010 at 4:02 PM
I guess you should create an issue. I will vote for it.
Aug 17, 2010 at 5:06 PM

http://avalondock.codeplex.com/workitem/11765

Done

Aug 26, 2010 at 1:53 PM

To get around this I've simply hid the content and manually remove the pane while keeping its parent and index stored in a tag. I did this all with extension methods.