[英]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();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.