繁体   English   中英

WPF DocumentViewer Find-function和FixedPage文档

[英]WPF DocumentViewer Find-function and FixedPage documents

.Net包含一个名为DocumentViewer的好控件。 它还提供了一个子控件,用于在加载的文档中查找文本(这至少是它应该做的事情)。

FixedPage的对象作为DocumentViewer文档源插入时,查找功能只是找不到任何内容。 甚至不是单个字母。 我还没有尝试过FlowDocument ,因为DocumentViewer没那么有用,并且网上的资源实际上并不存在,我现在想问一下stackoverflow社区:

使用FixedPage文档使WPF DocumentViewer的Find-Function需要什么?

[顺便说一下,我没有为DocumentViewer使用自定义ControlTemplates ]

我有与FixedDocuments相同的问题。 如果您将FixedDocument转换为XPS文档,那么它可以正常工作。

从FixedDocument在内存中创建XPS Document然后在DocumentViewer中显示的示例。

// Add to xaml: <DocumentViewer x:Name="documentViewer" />
// Add project references to "ReachFramework" and "System.Printing"
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.IO;
using System.IO.Packaging;
using System.Windows.Xps.Packaging;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // Set up demo FixedDocument containing text to be searched
            var fixedDocument = new FixedDocument();
            var pageContent = new PageContent();
            var fixedPage = new FixedPage();
            fixedPage.Children.Add(new TextBlock() { Text = "Demo document text." });
            pageContent.Child = fixedPage;
            fixedDocument.Pages.Add(pageContent);

            // Set up fresh XpsDocument
            var stream = new MemoryStream();
            var uri = new Uri("pack://document.xps");
            var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite);
            PackageStore.AddPackage(uri, package);
            var xpsDoc = new XpsDocument(package, CompressionOption.NotCompressed, uri.AbsoluteUri);

            // Write FixedDocument to the XpsDocument
            var docWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
            docWriter.Write(fixedDocument);

            // Display XpsDocument in DocumentViewer
            documentViewer.Document = xpsDoc.GetFixedDocumentSequence();
        }
    }
}

在此输入图像描述

我在richtextbox中搜索文本时遇到了麻烦,实在太慢了。 每次我想搜索时,我所做的就是缩小xaml。 我提高了几个数量级。

这是克里斯安德森的书中的一个重要的解决方法。

干杯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM