Home › Forums › WPF controls › Other WPF controls › AvalonDock: NullReferenceException when restoring state
Tagged: AvalonDock
-
AuthorPosts
-
#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); xmlLayout.Serialize(fs); 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); ser.Deserialize(sr); } }
I get a
NullReferenceException
on theDeserialize
command.Am I missing something or is this another bug?
Hi,
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}”>
<dock:DockingManager.LayoutItemContainerStyle>
<!– 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}” />
</Style>
</dock:DockingManager.LayoutItemContainerStyle>
</dock:DockingManager>Thanks, I actually forgot this… I will test this ASAP.
Followup: After I removed the custom
LayoutUpdateStrategy
and the default Layout, this works. Thanks for the help 🙂 -
AuthorPosts
- You must be logged in to reply to this topic.