[英]WPF RichTextBox: save/load in custom format
I need to load/save data from the WPF RichTextBox in a custom format (similar to Markdown). 我需要以自定义格式(类似于Markdown)从WPF RichTextBox加载/保存数据。
RichTextBox supports saving/loading in several basic formats (Rtf, Text, Xaml) using TextRange.Save method: RichTextBox支持使用TextRange.Save方法以几种基本格式(Rtf,Text,Xaml)保存/加载:
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. 我能想到的一种方法是将TextRange作为Xaml保存到内存流中,解析生成的XML并迭代它以进行转换。 Is there an easier way?
有更容易的方法吗?
Extended Toolkit提供了这样的RichTextBox控件
From all the DataFormat.Format
s available only 4 are compatible with TextRange.Save
: 从所有可用的
DataFormat.Format
只有4个与TextRange.Save
兼容:
Currently supported data formats are DataFormats.Rtf, DataFormats.Text, DataFormats.Xaml, and DataFormats.XamlPackage
目前支持的数据格式是DataFormats.Rtf,DataFormats.Text,DataFormats.Xaml和DataFormats.XamlPackage
source: http://msdn.microsoft.com/en-us/library/ms598701.aspx 来源: 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. 从我在这个类的反映中看到的,DataFormats没有提供添加新格式的API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.