[Version 1.3] DockableContent::RestoreLayout

Jul 29, 2010 at 5:04 PM
Edited Jul 29, 2010 at 5:10 PM
I saw one other post on this, but no resolution.

I've gotten DockManager Save/Restore Layout working. Then, I realized, what I probably really want is that each of my tools opens in the size and place that it was last used in. This doesn't necessarily mean it should be reopened with a bunch of other tools.

The mechanism by which DockManager Save/Restore layout seems to work best is if you create your document contents with the same name as they had when the layout was saved, then you restore the DockManager layout. The DockManager then places everything in its proper place.

So, now, what happens if I have a DockableContent that is created after a DockManager layout has been restored? It has the same name as that saved in the layout, it is just not created at the time of the restoration. My thought was that I should be able to call DockableContent::RestoreLayout to place it in the proper place once I create it.

Here is an example of the layout save file:

<DockingManager version="1.3.0">
<ResizingPanel ResizeWidth="*" ResizeHeight="*" EffectiveSize="0,0" Orientation="Vertical">
<ResizingPanel ResizeWidth="*" ResizeHeight="*" EffectiveSize="1008,327.54" Orientation="Horizontal">
<DockablePane ResizeWidth="250" ResizeHeight="*" EffectiveSize="250,667.08" ID="abfd747b-64a3-4524-b097-d49af4ddce36" Anchor="Left" IsAutoHidden="false" />
<DocumentPane IsMain="true" ResizeWidth="*" ResizeHeight="*" EffectiveSize="1008,327.54"> <DocumentContent Name="ID_6a1932faed364f34ac12fb9f3c3cf089" />
<DockablePane ResizeWidth="*" ResizeHeight="333.54" EffectiveSize="1008,333.54" ID="fb5637b5-0538-4721-ae46-d5bd0d88b790" Anchor="Bottom" IsAutoHidden="false">
<DockableContent Name="ID_1b5b7daeca44421fb6e0b860946c3988" FloatingWindowSize="250,400" ChildIndex="0" Width="250" Height="667.08" Anchor="Left" State="Docked" ContainerPaneID="abfd747b-64a3-4524-b097-d49af4ddce36" />
<Hidden />
<Windows />

And here is the way I'm accessing the element I want to restore:

toolWrapper = new DockableContent();

toolWrapper.Content = viewModel;
toolWrapper.Name = "ID_1b5b7daeca44421fb6e0b860946c3988";
toolWrapper.Show(DockManager, AnchorStyle.Left);
if (RestoreLayoutFilename != String.Empty && File.Exists(RestoreLayoutFilename))
XmlDocument doc = new XmlDocument();
XmlElement root = doc.DocumentElement;
XmlElement node = (XmlElement)root.SelectSingleNode("//DockableContent[@Name='ID_1b5b7daeca44421fb6e0b860946c3988']");


I find the node, but calling toolWrapper.RestoreLayout doesn't seem to do anything. I could call "DockManager.RestoreLayout", but the problem there is that if the user has moved other tools around, RestoreLayout might move those tools back to where they were last saved, instead of just the tool that was created. I guess I could do something silly like save the layout everytime I show, but that seems like a very dirty solution. All of this is with AvalonDock build 62949. Thoughts?
Jul 29, 2010 at 5:05 PM
Edited Jul 29, 2010 at 5:09 PM
Ugh - I had this all spaced out correctly - but for some reason this wiki doesn't understand returns/spaces, etc. Can someone tell me what I need to do to get this to format correctly? Edit: nevermind - I have to write in HTML - sigh...