Serialize WPF component using XamlWriter without default constructor
- by mizipzor
Ive found out that you can serialize a wpf component, in my example a FixedDocument, using the XamlWriter and a MemoryStream:
FixedDocument doc = GetDocument();
MemoryStream stream = new MemoryStream();
XamlWriter.Save(doc, stream);
And then to get it back:
stream.Seek(0, SeekOrigin.Begin);
FixedDocument result = (FixedDocument)XamlReader.Load(stream);
return result;
However, now I need to be able to serialize a DocumentPage as well. Which lacks a default constructor which makes the XamlReader.Load call throw an exception.
Is there a way to serialize a wpf component without a default constructor?