本文介绍了AvalonDock DockingManager不加载布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了保存和载入我的布局我跟着指示的,但它并没有为我工作。

In order to save and load my layout I followed the instructions here, but it didn't work for me.

我这有 XAML 中的主窗口

<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>

下面问题来了 - 之后我点击Load按钮文档和anchorable消失和所有我能在窗口中看到是2个按钮和一个空矩形在我的布局应该是。在这一点上,当我点击保存按钮,这就是被写入测试的文件:

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>



我使用AvalonDock 2.0.1746.0。任何人都知道如何解决它。

I am using AvalonDock 2.0.1746.0. Anyone knows how to fix it?

推荐答案

我想你的代码出来,相比它的输出到矿,并发现您的序列化的文件丢失了你的 LayoutDocument 内容识别属性C>和 LayoutAnchorable 。此属性是什么AvalonDock内部使用与序列化的版本匹配现有的 DockingManager 板,没有它,正如你所看到的,没有什么工作。

I tried your code out, and compared it's output to mine, and found that your serialized file is missing the ContentId property for your LayoutDocument and LayoutAnchorable. This property is what AvalonDock uses internally to match up the existing DockingManager panels with the serialized versions, and without it, as you have seen, nothing works.

也有2种方法可以用来设置内容识别属性,或明确为特定AvalonDock面板的财产,或含蓄通过设置名称属性面板上的直接孩子。这里是使用两种方式修改后的主窗口XAML代码

There are also 2 methods that can be used to set the ContentId property, either explicitly as a property of the specific AvalonDock panel, or implicitly by setting the Name property on the immediate child of the panel. Here is your revised main window XAML code with both ways used.

<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" ContentId="IHaveContent">
                        <TextBox />
                    </ad:LayoutDocument>
                </ad:LayoutDocumentPane>
            </ad:LayoutPanel>
            <ad:LayoutRoot.LeftSide>
                <ad:LayoutAnchorSide>
                    <ad:LayoutAnchorGroup>
                        <ad:LayoutAnchorable Title="Left">
                            <TextBox x:Name="IAmTextBoxContent"/>
                        </ad:LayoutAnchorable>
                    </ad:LayoutAnchorGroup>
                </ad:LayoutAnchorSide>
            </ad:LayoutRoot.LeftSide>
        </ad:LayoutRoot>
    </ad:DockingManager>
</StackPanel>

如果您现在使用的Save和Load按钮,您将看到内容识别属性现在设置在测试文件,如下

If you use the Save and Load buttons now, you will see the ContentId properties are now set in the test file, as below.

<?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"
          ContentId="IHaveContent"
          LastActivationTimeStamp="04/17/2013 09:13:35" />
    </LayoutDocumentPane>
  </RootPanel>
  <TopSide />
  <RightSide />
  <LeftSide>
    <LayoutAnchorGroup>
      <LayoutAnchorable AutoHideMinWidth="100"
          AutoHideMinHeight="100"
          Title="Left"
          ContentId="IAmTextBoxContent" />
    </LayoutAnchorGroup>
  </LeftSide>
  <BottomSide />
  <FloatingWindows />
  <Hidden />
</LayoutRoot>

有关将来如何调试这个问题的参考,我没有实际使用下面的回调,以调试并检查由反序列化过程,其中电子参数包含AvalonDock面板中的反序列化的版本,返回的值型号属性(在你的情况本来是空),如果内容识别属性是正确的,将包含在其内容您面板的内容属性(这也是空由于内容识别属性null值>模型) 。

For future reference on how to debug this issue, I did actually use the callback below in order to debug and check the values returned by the deserialization process, where the e parameter contains the deserialized version of the AvalonDock panel in the Model property, (which in your case was originally null), and if the ContentId property is correct, will contain you panel's content in its Content property (this was also null due to the null value in the ContentId property of the Model).

取值回调处理程序包含 XmlLayoutSerializer 基准,其中还包含对 DockingManager ,通过它你可以检查它所包含的经常项目的参考。

The s in the callback handler contains the XmlLayoutSerializer reference, which also contains a reference to the DockingManager, through which you can inspect the current items contained within it.

我记得有与AvalonDock的早期版本类似的问题,但我认为,固定它,我被升级到最新版本(你已经有了),因为有一个内部的部分不正确反序列化。

I remember having a similar issue with an earlier version of the AvalonDock, but I think what fixed it for me was upgrading to the latest version (which you already have), as there was an internal part not deserializing properly.

不过,要尽量找到反序列化过程中,你可以尝试把一个断点在 LayoutSerializer 回调的问题。希望这会给你以特定的问题是什么的详细信息。

However, to try find the issue with the deserialization process you could try putting a breakpoint in the LayoutSerializer callback. Hopefully that will give you more information as to what the particular issue is.

layoutSerializer.LayoutSerializationCallback += (s, e) =>
{
    object o = e.Content;
};

这篇关于AvalonDock DockingManager不加载布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 00:33