This project is read-only.

AvalonDock 2.0 getting started guide PART 2

In the part of the guide will se how to use AvalonDock common features. Starting from a simple layout, we'll see how to serialize/deserialize the layout and how to interact wtih it by code.

        <avalonDock:DockingManager x:Name="dockingManager">
                <avalonDock:LayoutPanel Orientation="Horizontal">
                    <avalonDock:LayoutAnchorablePane DockWidth="100">
                        <avalonDock:LayoutAnchorable Title="Tool 1" IconSource="/AvalonDock2Tutorial;component/Images/alarm-clock-blue.png">
                        <avalonDock:LayoutDocument Title="Doc1">
                            <avalonDock:LayoutAnchorable Title="Autohidden Content" IconSource="/AvalonDock2Tutorial;component/Images/address-book-open.png">

To save the layout we need the XmlLayoutSerializer class and call its Serialize method:
            var serializer = new XmlLayoutSerializer(dockingManager);
            using (var stream = new StreamWriter(fileName))

and the Deserialize method to load a layout from a file:
            var serializer = new XmlLayoutSerializer(dockingManager);
            using (var stream = new StreamReader(fileName))

If you put this code inside the application and run it you will shortly discover that even if the layout is correctly saved and loaded it doesn't restore controls inside the LayoutContent (in this case all textboxes). The problem is that AvalonDock when saving a layout stores only layout information. If you open the saved file you should see something like the following:

Last edited Sep 3, 2012 at 2:04 PM by adospace, version 2


NickStrupat Jan 29, 2013 at 2:46 PM 
For more info, my question on stackoverflow is at

NickStrupat Jan 29, 2013 at 2:25 PM 
How do we bind the layout of a DockingManager to a property on a view-model? My goal is to load a layout when our "project file" is opened, but I can't find an event or property that loads the layout properly. I've tried DataContextChanged but I think it fires too early because the layout loads with the documents in the hidden section and duplicate documents in the visible sections. Thanks!