This project has moved. For the latest updates, please go here.
2
Vote

AvalonDock: Serialization broken at least since 3.2.

description

If using MVVM bindings (AnchorablesSource and DocumentsSource) both the serialization and the deserialization of the layout is completely broken. Docking panels to the top or bottom won't get saved at all.

The easiest way to reproduce this is to check out this example: https://www.codeproject.com/Articles/719143/AvalonDock-Tutorial-Part-Load-Save-Layout where the saving still works and then update the AvalonDock to the latest version and see that the serialization is broken.

comments

BoucherS wrote Mar 6 at 2:43 PM

Hi,

Yes, there is a bug.
Upon de-serialization, a new RootPanel is created, but its orientation is always horizontal. This explains why when you dock a LayoutAnchorable on top/bottom, the de-serialization shows you horizontal panels, instead of Vertical panels.

You can fix if by going in file Xceed.Wpf.AvalonDock/Layout/LayoutRoot.cs, and doing the 2 fixes :
1) in method "ReadXml", replace :
var layoutPanelElements = this.ReadRootPanel( reader );
  if( layoutPanelElements != null )
  {
    this.RootPanel = new LayoutPanel();
    //Add all children to RootPanel
    for( int i = 0; i < layoutPanelElements.Count; ++i )
    {
      this.RootPanel.Children.Add( layoutPanelElements[ i ] );
    }
  }
with

Orientation orientation;
  var layoutPanelElements = this.ReadRootPanel( reader, out orientation );
  if( layoutPanelElements != null )
  {
    this.RootPanel = new LayoutPanel() { Orientation = orientation };
    //Add all children to RootPanel
    for( int i = 0; i < layoutPanelElements.Count; ++i )
    {
      this.RootPanel.Children.Add( layoutPanelElements[ i ] );
    }
  }
2) Replace the "ReadRootPanel" method with the following :
private List<ILayoutPanelElement> ReadRootPanel( XmlReader reader, out Orientation orientation )
{
  orientation = Orientation.Horizontal;
  var result = new List<ILayoutPanelElement>();

  var startElementName = reader.LocalName;
  reader.Read();
  if( reader.LocalName.Equals( startElementName ) && ( reader.NodeType == XmlNodeType.EndElement ) )
  {
    return null;
  }

  while( reader.NodeType == XmlNodeType.Whitespace )
  {
    reader.Read();
  }

  if( reader.LocalName.Equals( "RootPanel" ) )
  {
    orientation = (reader.GetAttribute( "Orientation" ) == "Vertical") ? Orientation.Vertical : Orientation.Horizontal;
    reader.Read();

    while( true )
    {
      //Read all RootPanel children
      var element = ReadElement( reader ) as ILayoutPanelElement;
      if( element != null )
      {
        result.Add( element );
      }
      else if( reader.NodeType == XmlNodeType.EndElement )
      {
        break;
      }
    }
  }

  reader.ReadEndElement();

  return result;
}

BoucherS wrote Mar 6 at 2:43 PM

――――
Get more controls, features, updates and technical support with Xceed Toolkit Plus for WPF

Dige wrote Mar 16 at 12:26 PM

Thanks!

Can I expect a fix for this in the next release? I'd rather keep using the Nuget-packages than keep compiling own versions.

BoucherS wrote Mar 16 at 6:42 PM

Hi,

Yes, this will be fixed in v3.4.

――――
Get more controls, features, updates and technical support with Xceed Toolkit Plus for WPF