AvalonDock没有正确反序列化LayoutRoot方向

时间:2017-06-05 15:55:15

标签: c# wpf avalondock

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

使用AvalonDock 3.3.17121.18230

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

我的布局是一个LayoutPanel,Orientation =“Vertical”,然后嵌套在3个LayoutPanels中,Orientation =“Horizo​​ntal”。第一个水平面板只是TOP,后面是另一个包含3个左/中/右面板的水平面板,然后是最后的水平面板,即BOTTOM面板。

看起来无论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>

正如您所看到的,它就像deserialize方法并不关心RootPanel Orientation =“Vertical”并始终加载它就像RootPanel Orientation =“Horizo​​ntal”

有人可以试试这个来理智地检查我,或者如果我发生了这个错误让我知道。我只是想保存从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);
    }
}

1 个答案:

答案 0 :(得分:0)

工具包v3.4在反序列化时已经有一个垂直方向的修复程序。 Toolkit v3.4现已发布,2017年6月5日。 我建议你尝试一下。

---- 通过Xceed Toolkit Plus for WPF

获取更多控件,功能,更新和技术支持