I'm trying to figure out how to use AvalonDock. I'm not limited to MVVM and quite happy to make the following work with code-behind WPF.
I have the following Method which opens a new AvalonDock LayoutDocument
and adds a WPF user control to it.
Before opening a new LayoutDocument
, the Method checks that the title of the new LayoutDocument
doesn't already exist in LayoutDocumentPane
.
This almost seems to work well.
The problem is that if the LayoutDocument
being opened already exists and has been un-anchored from LayoutDocumentPane
then it no longer exists in LayoutDocumentPane
.
How can I search for all LayoutDocument
regardless of where they are anchored?
Method as follows:
private void OpenWindow(string title, System.Windows.Controls.UserControl userControl)
{
var firstDocumentPane = dockManager.Layout.Descendents().OfType<LayoutDocumentPane>().FirstOrDefault();
if (firstDocumentPane != null)
{
bool addChild = true;
foreach (LayoutDocument child in LayoutDocumentPane.Children)
{
if (child.Title == title)
{
child.IsSelected = true;
addChild = false;
}
}
if (addChild == true)
{
LayoutDocument doc = new LayoutDocument();
doc.Title = title;
doc.Content = userControl;
doc.IsSelected = true;
firstDocumentPane.Children.Add(doc);
}
}
}
I've figured it out.
The following will list all LayoutDocument
documents in dockManager
var currentContentsList = dockManager.Layout.Descendents().OfType<LayoutDocument>().ToArray();
then loop through as follows:
foreach (LayoutDocument child in currentContentsList)
{
child.IsActive = true;
}