I have implemented ILayoutupdateStrategy using examples here but so far, each new LayoutDocument is always placed in the same LayoutDocumentPane. I would like to add the new LayoutDocument alongside an existing Document automatically.
I've tried creating a new LayoutDocumentPaneGroup and moving the existing LayoutDocumentPane, plus the new content into that new group, but when I then try to add the group into the layout structure the methods never return and the application hangs.
LayoutDocumentPaneGroup newGroup = { a LayoutDocumentPaneGroup containing both the original sibling LayoutDocumentPane and the new content LayoutDocumentPane }
LayoutDocumentPaneGroup parent = { the parent group of the sibling document }
I've tried things like:
parent.RemoveChild(sibling);
parent.Children.Add( newGroup );
and
parent.Children.ReplaceChild( sibling, newGroup );
but they all seem to hang on those methods.
I expect I'm approaching this in the wrong way completely so any pointers would be very welcome.
So... it turns out the problem was that you must defer adding children to the new document group being added until after it's been placed into the layout tree.
Example code
private void DockDocumentToBottom( LayoutDocumentPane sibling, LayoutDocument tobeDocked )
{
LayoutDocumentPaneGroup newGroup = new LayoutDocumentPaneGroup();
newGroup.Orientation = System.Windows.Controls.Orientation.Vertical;
LayoutDocumentPane newDocPane = new LayoutDocumentPane(tobeDocked);
LayoutDocumentPaneGroup siblingParent = sibling.Parent as LayoutDocumentPaneGroup;
if (siblingParent != null )
{
siblingParent.ReplaceChild(sibling, newGroup);
newGroup.Children.Add(sibling);
newGroup.Children.Add(newDocPane);
}
else
{
Debug.WriteLine("LayoutInitialiser: Failed to attach to a document pane group!");
}
}
I hope this helps someone else!