AvalonDock 未正确反序列化 LayoutRoot 方向

AvalonDock not Deserializing LayoutRoot orientation correctly

这真令人沮丧,想弄清楚这是一个错误还是我是个白痴。

使用 AvalonDock 3.3.17121.18230

我有一个简单的顶部、底部、Left/Center/Right 面板布局。使用 XAML 中指定的面板属性在初始加载期间一切正常。使用 XmlLayoutSerializer 的 .Serialize 保存布局后,文本文件中的所有内容看起来都很好。但是,当使用反序列化重新加载布局时,布局加载不正确,并将顶部和底部面板放置在中心 Left/Center/Right 面板的左侧和右侧。

我的layout是一个Orientation="Vertical"的LayoutPanel,然后里面嵌套了3个Orientation="Horizontal"的LayoutPanel。第一个水平面板只是顶部,然后是另一个包含 3 个 Left/Center/Right 面板的水平面板,然后是最后一个水平面板,即底部面板。

似乎无论 Rootpanels 布局方向如何,它总是将其反序列化为水平,即使它明确表示垂直。

Initial load from XAML properties - all ok

序列化文件内容:

<?xml version="1.0" encoding="utf-8"?>
<LayoutRoot>
  <RootPanel Orientation="Vertical">
    <LayoutPanel Orientation="Horizontal">
      <LayoutAnchorablePane DockHeight="100">
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="ShellTop" IsSelected="True" ContentId="ShellTop" CanClose="False" />
      </LayoutAnchorablePane>
    </LayoutPanel>
    <LayoutPanel Orientation="Horizontal">
      <LayoutAnchorablePane>
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="ShellLeft" IsSelected="True" ContentId="ShellLeft" CanClose="False" />
      </LayoutAnchorablePane>
      <LayoutAnchorablePane>
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="ShellMain" IsSelected="True" ContentId="ShellMain" CanClose="False" />
      </LayoutAnchorablePane>
      <LayoutAnchorablePane>
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="ShellRight" IsSelected="True" ContentId="ShellRight" CanClose="False" />
      </LayoutAnchorablePane>
    </LayoutPanel>
    <LayoutPanel Orientation="Horizontal">
      <LayoutAnchorablePane>
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="ShellBottom" IsSelected="True" ContentId="ShellBottom" CanClose="False" />
      </LayoutAnchorablePane>
    </LayoutPanel>
  </RootPanel>
  <TopSide />
  <RightSide />
  <LeftSide />
  <BottomSide />
  <FloatingWindows />
  <Hidden />
</LayoutRoot>

After serializing, then deserializing - not ok

保存损坏的布局后序列化文件的内容:

<?xml version="1.0" encoding="utf-8"?>
<LayoutRoot>
  <RootPanel Orientation="Horizontal">
    <LayoutPanel Orientation="Horizontal">
      <LayoutAnchorablePane DockHeight="100">
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="ShellTop" IsSelected="True" ContentId="ShellTop" CanClose="False" />
      </LayoutAnchorablePane>
    </LayoutPanel>
    <LayoutPanel Orientation="Horizontal">
      <LayoutAnchorablePane>
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="ShellLeft" IsSelected="True" ContentId="ShellLeft" CanClose="False" />
      </LayoutAnchorablePane>
      <LayoutAnchorablePane>
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="ShellMain" IsSelected="True" ContentId="ShellMain" CanClose="False" />
      </LayoutAnchorablePane>
      <LayoutAnchorablePane>
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="ShellRight" IsSelected="True" ContentId="ShellRight" CanClose="False" />
      </LayoutAnchorablePane>
    </LayoutPanel>
    <LayoutPanel Orientation="Horizontal">
      <LayoutAnchorablePane>
        <LayoutAnchorable AutoHideMinWidth="100" AutoHideMinHeight="100" Title="ShellBottom" IsSelected="True" ContentId="ShellBottom" CanClose="False" />
      </LayoutAnchorablePane>
    </LayoutPanel>
  </RootPanel>
  <TopSide />
  <RightSide />
  <LeftSide />
  <BottomSide />
  <FloatingWindows />
  <Hidden />
</LayoutRoot>

如您所见,反序列化方法似乎不关心 RootPanel Orientation="Vertical" 并始终像 RootPanel Orientation="Horizontal"

一样加载它

有人可以试试这个来检查我的理智吗,或者如果我做错了请告诉我。我只是想保存从 XAML 属性加载的状态,我不得不认为这是一个错误。

这是我的 XAML

的网格控件
<Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="20"/>
            <RowDefinition Height="20"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*"></ColumnDefinition>
            <ColumnDefinition Width="1*"></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <Button Grid.Row="0" Grid.Column="0" Content="Save Layout" Click="SaveButton_Click"/>
        <Button Grid.Row="0" Grid.Column="1" Content="Restore Layout" Click="RestoreButton_Click"/>
        <Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Content="Default Layout" Click="DefaultButton_Click"/>


        <avalonDock:DockingManager AllowMixedOrientation="True" x:Name="DManager" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Loaded="dockManager_Loaded">
            <avalonDock:LayoutRoot>

                <avalonDock:LayoutPanel Orientation="Vertical">

                    <avalonDock:LayoutPanel Orientation="Horizontal">

                        <avalonDock:LayoutAnchorablePane DockHeight="100">
                        <avalonDock:LayoutAnchorable Title="ShellTop" ContentId="ShellTop">
                            <Button Content="TOP"/>
                        </avalonDock:LayoutAnchorable>
                    </avalonDock:LayoutAnchorablePane>

                    </avalonDock:LayoutPanel>



                    <avalonDock:LayoutPanel Orientation="Horizontal">

                        <avalonDock:LayoutAnchorablePane>
                            <avalonDock:LayoutAnchorable Title="ShellLeft" ContentId="ShellLeft">
                                <Button Content="LEFT"/>
                            </avalonDock:LayoutAnchorable>
                    </avalonDock:LayoutAnchorablePane>

                    <avalonDock:LayoutAnchorablePane>
                            <avalonDock:LayoutAnchorable Title="ShellMain" ContentId="ShellMain">
                                <Button Content="MIDDLE"/>
                            </avalonDock:LayoutAnchorable>
                    </avalonDock:LayoutAnchorablePane>

                        <avalonDock:LayoutAnchorablePane>
                            <avalonDock:LayoutAnchorable Title="ShellRight" ContentId="ShellRight">
                                <Button Content="RIGHT"/>
                            </avalonDock:LayoutAnchorable>
                        </avalonDock:LayoutAnchorablePane>

                    </avalonDock:LayoutPanel>


                    <avalonDock:LayoutPanel Orientation="Horizontal">

                            <avalonDock:LayoutAnchorablePane>
                        <avalonDock:LayoutAnchorable Title="ShellBottom" ContentId="ShellBottom">
                            <Button Content="BOTTOM"/>
                        </avalonDock:LayoutAnchorable>
                    </avalonDock:LayoutAnchorablePane>

                    </avalonDock:LayoutPanel>



                </avalonDock:LayoutPanel>


            </avalonDock:LayoutRoot>
        </avalonDock:DockingManager>
    </Grid>

代码隐藏

private void SaveButton_Click(object sender, RoutedEventArgs e)
{
    XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(DManager);
    using (var writer = new StreamWriter("C:/Users/xxx/Desktop/test.txt"))
    {
        layoutSerializer.Serialize(writer);
    }
}

private void RestoreButton_Click(object sender, RoutedEventArgs e)
{
    XmlLayoutSerializer layoutSerializer = new XmlLayoutSerializer(DManager);
    using (var reader = new StreamReader("C:/Users/xxx/Desktop/test.txt"))
    {
        layoutSerializer.Deserialize(reader);
    }
}

Toolkit v3.4 已经修复了反序列化时的垂直方向。 Toolkit v3.4 于今天(2017 年 6 月 5 日)可用。 我建议你试试看。

—————— 通过 Xceed Toolkit Plus for WPF

获得更多控件、功能、更新和技术支持