【问题标题】:Load .txt into a FlowDocumentScrollViewer?将 .txt 加载到 FlowDocumentScrollViewer 中?
【发布时间】:2014-05-13 17:52:14
【问题描述】:

我正在动态创建 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);

【问题讨论】:

  • 你没有。您在 FlowDocumentScrollViewer 中显示一个 FlowDocument。
  • 你能帮我写一个相同的代码 sn-p 吗?
  • 不一样。 FlowDocumentScrollViewer 不显示纯文本。 msdn.microsoft.com 上有关于如何创建 FlowDocument 的示例。

标签: c# wpf file load flowdocumentscrollviewer


【解决方案1】:

知道了:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    相关资源
    最近更新 更多