将 RTF 转换为 FlowDocument 的最快方法是什么?我将 RTF 存储为纯字符串,然后重新加载它,我使用以下方法,
FlowDocument document = new FlowDocument();
document.SetValue(FlowDocument.TextAlignmentProperty, TextAlignment.Left);
TextRange content = new TextRange(document.ContentStart, document.ContentEnd);
if (content.CanLoad(DataFormats.Rtf) && string.IsNullOrEmpty(rtf) == false)
{
// If so then load it with RTF
byte[] valueArray = Encoding.ASCII.GetBytes(rtf);
using (MemoryStream stream = new MemoryStream(valueArray))
{
content.Load(stream, DataFormats.Rtf);
}
}
但是这种方法很慢。我需要加载许多 RTF(大约 1000 个)。加快这个过程的诀窍是什么?有没有其他方法可以加载 Flowdocument?