How to serialize a class that has both of two worlds
-
hi, I want to serialize a class which has the two kinds of elements. Custom elements (non graphic and made by me, which are serializable by the XmlSerializer), and UI Elements from the WPF. The class which i want to serialize is this: Code Snippet public class Region : ISerializable { private Control _control; public Control Control { get { return _control; } set { _control = value; } } private Border _bounds; public Border Bounds { get { return _bounds; } set { _bounds = value; } } public Region() { } /// /// Initializes a new instance of the class. /// public Region(Border bounds) { _bounds = bounds; } public Region(SerializationInfo info, StreamingContext ctxt) { this._control = (Control)info.GetValue("Control", typeof(Control)); this._bounds = (Border)XamlReader.Load(new XmlTextReader(new StringReader((string)info.GetValue("Bounds", typeof(string))))); } public void GetObjectData(SerializationInfo info, StreamingContext ctxt) { info.AddValue("Control", this._control); info.AddValue("Bounds", XamlWriter.Save(_bounds)); } } As you can see, this class is composed by a Control (custom made class specified by me) and a Border (UI Element). The class was serializable if i didnt have the border on it. My attempt was to override the Iserialize methods in order to have serialization of the border based on XamlWriter.Save but it gives me error before getting there, in the following line: Code Snippet System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(Region)); With the message: Code Snippet "There was an error reflecting property 'Bounds'." How can i solve this problem? Thx, Nuno