[英]WPF DocumentViewer Find-function and FixedPage documents
.Net contains a nice control called DocumentViewer
. .Net包含一个名为DocumentViewer
的好控件。 it also offers a subcontrol for finding text in the loaded document (that's at least what it is supposed to do). 它还提供了一个子控件,用于在加载的文档中查找文本(这至少是它应该做的事情)。
When inserting FixedPage
's objects as document source for the DocumentViewer
, the find-functionality just does not find anything. 将FixedPage
的对象作为DocumentViewer
文档源插入时,查找功能只是找不到任何内容。 Not even single letters. 甚至不是单个字母。 I haven't tried FlowDocument
's yet, as the documentation for DocumentViewer
is not that useful and the resources on the net are not actually existing, I now want to ask the stackoverflow community: 我还没有尝试过FlowDocument
,因为DocumentViewer
没那么有用,并且网上的资源实际上并不存在,我现在想问一下stackoverflow社区:
What does it need to get the Find-Function of the WPF DocumentViewer
working with FixedPage
documents? 使用FixedPage
文档使WPF DocumentViewer
的Find-Function需要什么?
[btw, I don't use custom ControlTemplates
for DocumentViewer
] [顺便说一下,我没有为DocumentViewer
使用自定义ControlTemplates
]
I had this same problem with FixedDocuments. 我有与FixedDocuments相同的问题。 If you convert your FixedDocument to an XPS document then it works fine. 如果您将FixedDocument转换为XPS文档,那么它可以正常工作。
Example of creating an XPS Document in memory from a FixedDocument then displaying in a DocumentViewer. 从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();
}
}
}
I had trouble with searching text in richtextbox, it was too slow. 我在richtextbox中搜索文本时遇到了麻烦,实在太慢了。 What I did was crunch the xaml every time I wanted to search. 每次我想搜索时,我所做的就是缩小xaml。 I improved several orders of magnitude. 我提高了几个数量级。
It's a big workaround based in a part of the Chris Anderson's book . 这是克里斯安德森的书中的一个重要的解决方法。
Cheers 干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.