Load .txt into a FlowDocumentScrollViewer?

101 Views Asked by At

I am dynamically creating FlowDocumentScrollViewer how do I open .txt file in FlowDocumentScrollViewer? I used this when I had richtextbox, but how do I do the same in FlowDocumentScrollViewer?

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

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

There are 1 best solutions below

0
On

Got it:

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;
}