In order to save and load my layout I followed the instructions here, but it didn't work for me.
I've got this XAML
inside the MainWindow
:
<StackPanel Orientation="Vertical">
<Button Content="Save"
Click="SaveButton_Click"/>
<Button Content="Load"
Click="LoadButton_Click"/>
<ad:DockingManager x:Name="myDM">
<ad:LayoutRoot>
<ad:LayoutPanel>
<ad:LayoutDocumentPane>
<ad:LayoutDocument Title="Document">
<TextBox />
</ad:LayoutDocument>
</ad:LayoutDocumentPane>
</ad:LayoutPanel>
<ad:LayoutRoot.LeftSide>
<ad:LayoutAnchorSide>
<ad:LayoutAnchorGroup>
<ad:LayoutAnchorable Title="Left">
<TextBox/>
</ad:LayoutAnchorable>
</ad:LayoutAnchorGroup>
</ad:LayoutAnchorSide>
</ad:LayoutRoot.LeftSide>
</ad:LayoutRoot>
</ad:DockingManager>
</StackPanel>
And these are the event handlers for the button clicks:
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(myDM);
using (var writer = new StreamWriter("test"))
{
layoutSerializer.Serialize(writer);
}
}
private void LoadButton_Click(object sender, RoutedEventArgs e)
{
XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(myDM);
using (var reader = new StreamReader("test"))
{
layoutSerializer.Deserialize(reader);
}
}
After the window is shown and I click save the content of the "test" file is:
<?xml version="1.0" encoding="utf-8"?>
<LayoutRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RootPanel Orientation="Horizontal">
<LayoutDocumentPane>
<LayoutDocument Title="Document" IsSelected="True" IsLastFocusedDocument="True" LastActivationTimeStamp="04/12/2013 14:50:38" />
</LayoutDocumentPane>
</RootPanel>
<TopSide />
<RightSide />
<LeftSide>
<LayoutAnchorGroup>
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Left" />
</LayoutAnchorGroup>
</LeftSide>
<BottomSide />
<FloatingWindows />
<Hidden />
</LayoutRoot>
Here comes the problem - after I click the load button the document and the anchorable disappear and all I can see in the window are the 2 buttons and an empty rectangle where my layout should be. At this point when I click the save button this is what is written to the "test" file:
<?xml version="1.0" encoding="utf-8"?>
<LayoutRoot xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RootPanel Orientation="Horizontal">
<LayoutDocumentPane />
</RootPanel>
<TopSide />
<RightSide />
<LeftSide>
<LayoutAnchorGroup Id="d3710e74-e6b5-4541-8b6f-554197c29dd6" />
</LeftSide>
<BottomSide />
<FloatingWindows />
<Hidden>
<LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="Left" IsSelected="True" LastActivationTimeStamp="04/12/2013 14:53:56" PreviousContainerId="d3710e74-e6b5-4541-8b6f-554197c29dd6" PreviousContainerIndex="0" />
</Hidden>
</LayoutRoot>
I am using AvalonDock 2.0.1746.0. Anyone knows how to fix it?