You should not persist the FlowDocument directly as it should be considered the runtime representation of the document, not the actual document content. Instead, use the TextRange class to Save and Load to various formats including Rtf.
A quick sample on how to create a selection and save to a stream:
var content = new TextRange(doc.ContentStart, doc.ContentEnd);
if (content.CanSave(DataFormats.Rtf))
{
using (var stream = new MemoryStream())
{
content.Save(stream, DataFormats.Rtf);
}
}
To load content into a selection would be similar:
var content = new TextRange(doc.ContentStart, doc.ContentEnd);
if (content.CanLoad(DataFormats.Rtf))
{
content.Load(stream, DataFormats.Rtf);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…