我一直在使用DockManager
和LayoutRoot
,LayoutAnchorablePane
和LayoutDocumentPane
。如何在關閉標籤後從DockManager中刪除LogicalChildren?
<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>
然而,有一個問題我已經中遇到的是,在DockManager.LogicalChildren
,該ContentPresenter
我UserControl
是走進LayoutDocument
當我關閉窗口永遠不會被取出,並保持建立越來越多的LogicalChildren
直到它開始減慢應用程序。
當我檢測到ChildrenCollectionChanged
時,如何刪除與LayoutDocument
關聯的ContentPresenter
和UserControl
?
編輯1:好的,那麼LogicalChildren
是System.Linq.Enumerable.WhereSelectListIterator<System.WeakReference,object>
,所以我將無法從該列表中刪除任何東西(也只擁有get
,並沒有set
)。
LayoutDocumentPane.RemoveChild()
方法不會對DockingManager.LogicalChildren
做任何事情,所以我不知道LogicalChildren
是從哪裏抽取迭代日期。
編輯2:所以,我試着添加一個事件到DocumentClosing
事件處理程序的DockManager
,它似乎仍然沒有從DockManager中刪除未使用的LogicalChildren
。
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();
}
}
編輯3:看DocumentClosed
後剩下的LayoutDocumentPane
不作任何修改(而不是DocumentClosing
)後,似乎用戶控件從LayoutDocumentPane
刪除,但不是從LogicalChildren
依然。
你使用的是什麼版本的avalondock? – Jehof
我以前也有過。我自己的解決方法是把AnchorablePane(加上Anchorable中的其他任何東西)和使用'LayoutDocumentPane'作爲工廠站點。我也像你一樣吸引了閉幕式。 –
@Jehof我正在使用v2.0.2000 –