Oct 13, 2008 at 11:27 PM
Edited Oct 13, 2008 at 11:28 PM
This is a great docking library and I'm trying to incorporate it into a client app where user layout persistence is crutial. I'm having a problem calling RestoreLayout on my document manager and having it restore panes that have be added to the manager
programmatically. Here's my XAML from a test project.
<ad:DockingManager Grid.Row="1" x:Name="dockManager">
<ad:ResizingPanel x:Name="resizePanel" Orientation="Vertical">
<ad:DockablePane x:Name="dockPane1" >
<TextBlock Text="This is some content" />
And here's my code behind:
DockableContent cnt = new
cnt.Name = "content2";
cnt.Content = new
cnt.Title = "New Textbox";
DockablePane pane =
pane.Name = "pane1";
The code will successfully add a new dockable pane with a textbox content every time it is called. Here is the XML string that is created when SaveLayout is called:
<DockablePane ResizeHeight="200" Anchor="Top">
<DockableContent Name="dockContent1" AutoHide="false" />
<DockableContent Name="content2" AutoHide="false" />
Everything looks good so far, but when restore layout is called, the 'content2' DockableContent and it's parent pane are not restored. Is this functionality possible with AvalonDock? There may just be something that I am overlooking.
Hi, you have to check if DockingManager.RestoreLayout() is called after you add 'content2'. When DockingManager restoring layout encounters a content with name 'content2', it looks for a content with that name in DockingManager.DockableContents array.
If it can't find the content it simply skips to next entry.
In my internal version (posted soon) I added a way to dynamically provide content to AvalonDock when it needs.
Thanks for your quick reply. You are correct, I was calling DockingManager.RestoreLayout() when the application loads. I was hoping that it would restore the panes and their positions and then I would extend the restore process and
dynamically add the content back into the restored panes if the end user chooses to.
What is the best way to add content to the DockingManager before DockingManager.RestoreLayout() is called? For example, if I have some content displayed in a floating window when DockingManager.SaveLayout() is called, and I restart my application,
re-add the content in a DockablePane and call DockingManager.RestoreLayout(), will it restore itself into a floating window?
If you need to manage correctly layout persistance the rigth way is always to add all contents at startup in a fixed layout. For an example all contents docked to the right. Then call the RestoreLayout and leave AvalonDock rearrange your contents according
to xml file. After this when user close the application or when you prefer call SaveLayout to store the layout again. You can even provide a default layout as xml file stored in an assemply resource, so the very first time your application starts you can provide
that to RestoreLayout().
This is the strategy used in SharpDevelop and I suggest you to take a look at that code.
In pseudo code:
<ad:DockingManager Grid.Row="1" x:Name="dockManager">(intentionally empty)
DockablePane dummyPane = new DockablePane()
foreach (Contents to load)
//here call restorelayout
Hope can help! Ado