Serialize WPF component using XamlWriter without default constructor

Posted by mizipzor on Stack Overflow See other posts from Stack Overflow or by mizipzor
Published on 2010-06-10T16:53:31Z Indexed on 2010/06/11 5:42 UTC
Read the original article Hit count: 486

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?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about serialization