views:

49

answers:

2

I need to load/save data from the WPF RichTextBox in a custom format (similar to Markdown).

RichTextBox supports saving/loading in several basic formats (Rtf, Text, Xaml) using 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 the custom format saving/loading?

One way I can think of is to save TextRange to a memory stream as Xaml, parse the resulting XML and iterate over it to do the conversion. Is there an easier way?

A: 

From all the DataFormat.Formats available only 4 are compatible with TextRange.Save:

Currently supported data formats are DataFormats.Rtf, DataFormats.Text, DataFormats.Xaml, and DataFormats.XamlPackage

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

And from what I saw in the reflection of this class the DataFormats doesn't provide an API to add new formats.

Jader Dias
+1  A: 

Extended Toolkit provide such a RichTextBox control

Bhuvan