Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Edited Issue: AvalonDock: Serialization broken at least since 3.2. [22494]

$
0
0
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: ** Comment from web user: BoucherS **

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


Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>