Hi,
The CompositeNode serialization is designed to work in two modes.
In the first (the default) mode, the composite nodes serialize their entire component hierarchy during saves and completely rebuild the component hierarchy during load. When using this mode, all references to components need to be updated after a node has been loaded because the component hierarchy has been replaced and the old component references are no longer relevant. To do this, override the LoadFromXml method of the CompositeNode class:
Protected Overrides Sub LoadFromXml(xmlElement As System.Xml.XmlElement, context As XmlPersistContext)
MyBase.LoadFromXml(xmlElement, context)
_title = CType(FindComponent("Title"), TextComponent)
_text = Ctype(FindComponent("Text"), TextComponent)
End Sub
However, due to a bug in the current deserialization logic, the old hierarchy is not removed during load and the new hierarchy is added alongside. Because of this, FindComponent will still return references to the old hierarchy. To fix this, you can call Components.Clear before invoking the base LoadFromXml. This bug will be fixed in the upcoming 6.0.1 release.
In the second serialization mode, the component hierarchy is not serialized. Instead of serializing the entire hierarchy, the client is expected to manually save/load only the variable values. This mode has the advantage of keeping the output file smaller and is recommended for cases such as yours, where the component hierarchy is statically defined for all instances of the CompositeNode class. To turn this mode on, override the SerializeComponents method and return False. Then, to manually save and load the variables, override SaveToXml and LoadFromXml and perform the necessary calls through the supplied XmlPersistContext:
Protected Overrides Function SerializeComponents() As Boolean
Return False
End Function
Protected Overrides Sub SaveToXml(xmlElement As System.Xml.XmlElement, context As XmlPersistContext)
MyBase.SaveToXml(xmlElement, context)
context.WritePen(Stroke, "ComponentStroke", xmlElement)
context.WriteBrush(Fill, "ComponentFill", xmlElement)
context.WriteImage(Image, "ComponentImage", xmlElement)
context.WriteString(Title, "ComponentTitle", xmlElement)
context.WriteString(Text, "ComponentText", xmlElement)
End Sub
Protected Overrides Sub LoadFromXml(xmlElement As System.Xml.XmlElement, context As XmlPersistContext)
MyBase.LoadFromXml(xmlElement, context)
Stroke = context.ReadPen("ComponentStroke", xmlElement)
Fill = context.ReadBrush("ComponentFill", xmlElement)
Image = context.ReadImage("ComponentImage", xmlElement)
Title = context.ReadString("ComponentTitle", xmlElement)
Text = context.ReadString("ComponentText", xmlElement)
End Sub
Note that there is no need to update the _title and _text references in this case since the component hierarchy has not changed during load. Also note that only the relevant values are written in the output XML file - the component hierarchy is no longer persisted.
I hope this clarifies things a bit.
Regards,
Meppy