Home Forums WPF controls Other WPF controls AvalonDock: NullReferenceException when restoring state


Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • rabjen-iwes
    Post count: 8
    #44499 |

    I have not yet tried the quick fix for the non-working tab titles on anchorables, so I don’t know if this is related to this.

    I took the AvalonDockLayoutSerializer from this tutorial on CodeProject, where the serialization boils down to this:

                using(StringWriter fs = new StringWriter()) {
                    XmlLayoutSerializer xmlLayout = new XmlLayoutSerializer(frameworkElement);
                    xmlLayoutString = fs.ToString();

    then, the xmlLayoutString is passed to a command where I save it.

    So far so good. When I try to load it again with this part of code I added:

            public static void LoadLayout(this DockingManager dm, string layoutXml) {
                using(var sr = new StringReader(layoutXml)) {
                    var ser = new XmlLayoutSerializer(dm);

    I get a NullReferenceException on the Deserialize command.

    Am I missing something or is this another bug?

    Fawzi [Xceed]
    Post count: 722


    We don’t have a sample to test your scenario, but make sure you have set the ContentId property for your LayoutDocuments and LayoutAnchorables. This is necessary in order for deserialization to work.
    Ex :

    <dock:DockingManager x:Name=”myDM”
    DataContext=”{StaticResource ViewModel}”
    AnchorablesSource=”{Binding Pages}”>
    <!– you can add additional bindings from the layoutitem to the DockWindowViewModel –>
    <Style TargetType=”{x:Type dockctrl:LayoutItem}”>
    <Setter Property=”Title”
    Value=”{Binding Model.Title}” />
    <Setter Property=”ContentId”
    Value=”{Binding Model.Title}” />

    Post count: 8

    Thanks, I actually forgot this… I will test this ASAP.

    Post count: 8

    Followup: After I removed the custom LayoutUpdateStrategy and the default Layout, this works. Thanks for the help 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.