문제

.NET에는 멋진 컨트롤이 포함되어 있습니다 DocumentViewer. 또한로드 된 문서에서 텍스트를 찾기위한 하위 제어를 제공합니다 (적어도해야 할 일).

삽입 할 때 FixedPage문서 소스로서의 객체 DocumentViewer, 찾기 기능은 아무것도 찾지 못합니다. 단일 문자조차도 아닙니다. 나는 시도하지 않았다 FlowDocument아직 문서로 DocumentViewer 그다지 유용하지 않으며 인터넷의 자원이 실제로 존재하지 않으므로 이제 StackoverFlow 커뮤니티에 물어보고 싶습니다.

WPF의 찾기 기능을 얻는 데 필요한 것은 무엇입니까? DocumentViewer 작업 FixedPage 서류?

BTW, 나는 커스텀을 사용하지 않습니다 ControlTemplates ~을 위한 DocumentViewer]

도움이 되었습니까?

해결책

고정 문서와 같은 문제가있었습니다. 고정 문서를 XPS 문서로 변환하면 정상적으로 작동합니다.

고정 문서에서 메모리에서 XPS 문서를 작성한 다음 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();
        }
    }
}

enter image description here

다른 팁

RichTextBox에서 텍스트를 검색하는 데 어려움이 있었는데 너무 느 렸습니다. 내가 한 일은 검색하고 싶을 때마다 XAML을 위기였습니다. 나는 몇 배의 순서를 개선했습니다.

Chris Anderson의 일부를 기반으로 한 큰 해결 방법입니다. .

건배

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top