C# 如何在RichTextBoxt上显示带有公式的RTF文档?

C# 如何在RichTextBoxt上显示带有公式的RTF文档?,c#,wpf-controls,richtextbox,C#,Wpf Controls,Richtextbox,我正在尝试将rtf文档加载到RichTextBox,如下所示: private void LoadTextDocument(string fileName) { Rtb.Document.Blocks.Clear(); TextRange range; System.IO.FileStream fStream; if (System.IO.File.Exists(fileName)) { range = new TextRange(Rtb.

我正在尝试将rtf文档加载到RichTextBox,如下所示:

private void LoadTextDocument(string fileName)
{
    Rtb.Document.Blocks.Clear();
    TextRange range;
    System.IO.FileStream fStream;
    if (System.IO.File.Exists(fileName))
    {
        range = new TextRange(Rtb.Document.ContentStart, Rtb.Document.ContentEnd);
        fStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open);
        range.Load(fStream, System.Windows.DataFormats.Rtf);
        fStream.Close();
    }
}
但文件中包含的公式高于应使用的公式


问题是,.NET RTF box甚至与使用OpenOffice、Word或其他编辑器创建的RTF文件不完全兼容。因此,我担心这项任务甚至不可能完成。 我花了几天时间试图用RichTextBox找到一个不同问题的解决方案(在Word中创建的更复杂的RTF中替换文本)


最后,我使用了一个正则表达式解决方案,不使用RTB直接替换文件中的文本。

请用示例中的第一行粘贴部分rtf