2014-05-13 33 views
0

我正在動態創建FlowDocumentScrollViewer如何在FlowDocumentScrollViewer中打開.txt文件? 我使用這個時,我有richtextbox,但我怎麼做在FlowDocumentScrollViewer相同?將.txt加載到FlowDocumentScrollViewer中?

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

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

你不知道。您在FlowDocumentScrollViewer中顯示一個FlowDocument。 – Paparazzi

+0

你能幫我一個代碼片段嗎? – user2495173

+0

沒有相同的。 FlowDocumentScrollViewer不顯示直線文本。在msdn.microsoft.com上有關於如何創建FlowDocument的示例。 – Paparazzi

回答

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; 
} 
相關問題