WPF RichTextBox: save / load in custom format

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?

+3
source share
2 answers

Extended Toolkit RichTextBox

+1

DataFormat.Format 4 TextRange.Save:

- DataFormats.Rtf, DataFormats.Text, DataFormats.Xaml DataFormats.XamlPackage

: http://msdn.microsoft.com/en-us/library/ms598701.aspx

, , DataFormats API .

0

Source: https://habr.com/ru/post/1771209/


All Articles