AvalonDock DockingManager does not load layout

后端 未结 1 1789
南旧
南旧 2021-01-01 01:26

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

相关标签:
1条回答
  • 2021-01-01 01:36

    Edit:

    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.

    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>
    

    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>
    

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

    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.

    Old:

    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.

    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;
    };
    
    0 讨论(0)
提交回复
热议问题