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

Mots-clés : 

4 sujets de 1 à 4 (sur un total de 4)
  • Auteur
  • 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 🙂

4 sujets de 1 à 4 (sur un total de 4)
  • Vous devez être connecté pour répondre à ce sujet.