我们如何在WPF中将.rtf或.doc文件显示为FlowDocument?

9

这是应用程序的帮助部分。我正在考虑使用FlowdocumentReader来显示帮助文档。但是,是否可能在Flowdocument中显示.rtf或任何.doc文件?或者必须在Xaml中创建flow document。请帮忙。

谢谢!

1个回答

15

以下代码可以完成你的需求,其中documentPath是你的rtf文件路径:

FileStream fileStream = File.Open(documentPath, FileMode.Open, FileAccess.Read, FileShare.Read);

FlowDocument flowDocument = new FlowDocument();

TextRange textRange = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);

textRange.Load(fileStream , DataFormats.Rtf);

不过确保加入错误检查代码。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接