为了保存和加载我的布局,我按照这里的说明进行操作,但它对我不起作用。
我在XAML
里面有这个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>
这些是按钮单击的事件处理程序:
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);
}
}
显示窗口后,我点击保存“测试”文件的内容是:
<?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>
问题来了 - 在我单击加载按钮后,文档和可锚定项消失了,我在窗口中看到的只有 2 个按钮和一个空矩形,我的布局应该是。此时,当我单击保存按钮时,这是写入“测试”文件的内容:
<?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>
我正在使用 AvalonDock 2.0.1746.0。任何人都知道如何解决它?