I need to load / save data from WPF RichTextBox in a custom format (similar to Markdown).
RichTextBox supports saving / loading in several basic formats (Rtf, Text, Xaml) using the TextRange.Save method :
using (FileStream fs = File.OpenWrite(file)) {
TextRange text = new TextRange(rtNote.Document.ContentStart, rtNote.Document.ContentEnd);
text.Save(fs, DataFormats.Xaml);
}
What is the best way to implement save / load custom format?
One way I can come up with is to save the TextRange in the memory stream as Xaml, parse the resulting XML and iterate over it for conversion. Is there an easier way?
source
share