I've been using the DockManager
with LayoutRoot
, LayoutAnchorablePane
and LayoutDocumentPane
.
<ad:DockingManager x:Name="dockManager" >
<adLayout:LayoutRoot>
<adLayout:LayoutPanel x:Name="myLayoutPanel" Orientation="Horizontal">
<adLayout:LayoutAnchorablePane x:Name="myLayoutAnchorablePane" DockWidth="400"/>
<adLayout:LayoutDocumentPane x:Name="myDocumentPane" ChildrenCollectionChanged="myDocumentPane_ChildrenCollectionChanged"/>
</adLayout:LayoutPanel>
</adLayout:LayoutRoot>
</ad:DockingManager>
However, one problem I've encounted is that in DockManager.LogicalChildren
, the ContentPresenter
and my UserControl
that went into the LayoutDocument
never gets removed when I close the window and keeps building up more and more LogicalChildren
until it starts to slow down the application.
How do I, when I detect ChildrenCollectionChanged
, remove the ContentPresenter
and UserControl
that were associated with that LayoutDocument
?
Edit 1: Okay, so LogicalChildren
is System.Linq.Enumerable.WhereSelectListIterator<System.WeakReference,object>
, so I won't be able to remove anything from that list (also it only has a get
, and no set
).
The LayoutDocumentPane.RemoveChild()
method doesn't do anything to the DockingManager.LogicalChildren
, so I can't figure out where the LogicalChildren
is pulling the iteration date from.
Edit 2: So, I tried adding an event to the DocumentClosing
event handler for DockManager
and it still doesn't seem to remove the unused LogicalChildren
from DockManager.
void dockManager_DocumentClosing(object sender, Xceed.Wpf.AvalonDock.DocumentClosingEventArgs e) {
UserControl uc = e.Document.Content as UserControl;
e.Cancel = true;
e.Document.IsActive = false;
if(uc != null) {
var u = myDocumentPane.Children.Where(a => a.Content.Equals(uc)).FirstOrDefault();
u.IsActive = false;
u.Close();
myDocumentPane.Children.Remove(u);
myDocumentPane.RemoveChild(u);
var oldLogicalParentPaneControl =
LogicalTreeHelper.GetParent(u.Content as UIElement) as Xceed.Wpf.AvalonDock.DockingManager;
oldLogicalParentPaneControl.Layout.RemoveChild(u);
oldLogicalParentPaneControl.Layout.CollectGarbage();
dockManager.UpdateLayout();
}
}
Edit 3: After looking at what remains in LayoutDocumentPane
after the DocumentClosed
without any modification (instead of DocumentClosing
), it seems that the User Control is removed from LayoutDocumentPane
, but not from LogicalChildren
still.