将.txt加载到FlowDocumentScrollViewer中?

时间:2014-05-13 17:52:14

标签: c# wpf file load flowdocumentscrollviewer

我正在动态创建FlowDocumentScrollViewer如何在FlowDocumentScrollViewer中打开.txt文件? 我使用richtextbox时使用了这个,但是如何在FlowDocumentScrollViewer中执行相同操作?

fStream = new FileStream(filePath, FileMode.OpenOrCreate);

range = new TextRange(mcRTB.Document.ContentStart, mcRTB.Document.ContentEnd);
                        range.Load(fStream, DataFormats.Text);

1 个答案:

答案 0 :(得分:0)

知道了:

FlowDocumentScrollViewer flowDocumentSV = new FlowDocumentScrollViewer();


                    try
                    {
                        fStream = new FileStream(filePath, FileMode.OpenOrCreate);
                        FlowDocument flowDocument = new FlowDocument();

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

                        range.Load(fStream, DataFormats.Text);
                        flowDocScrollViewer.Document = flowDocument;
}