如何使用 DocumentViewer 显示流文档? [英] How to show a flow document using a DocumentViewer?

查看:26
本文介绍了如何使用 DocumentViewer 显示流文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的资源中有一个简单的流文档,FlowDocument1.xaml:

I have a simple flow document in my resources, FlowDocument1.xaml:

<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          ColumnWidth="400" FontSize="14" FontFamily="Georgia">
    <Paragraph>
        Test
    </Paragraph>
</FlowDocument>

我想在 DocumentViewer 中显示此文档.我搜索了一个需要路径的属性,但我找不到.并且以下抛出异常:

And I want to show this document in a DocumentViewer. I searched for a property that takes path but I couldn't find one. And the following throws an exception:

<DocumentViewer x:Name="TestViewer" Document="Resources/FlowDocument1.xaml" />

如何在 DocumentViewer 中显示 FlowDocument1.xaml?

推荐答案

首先你不能将 FlowDocument 添加到 DocumentViewer 因为它只支持 FixedDocument.您可以改用 FlowDocumentScrollViewerFlowDocumentPageViewer.

First you cannot add a FlowDocument to a DocumentViewer because it only supports FixedDocument. You may use FlowDocumentScrollViewer or FlowDocumentPageViewer instead.

<FlowDocumentScrollViewer x:Name="TestViewer"/>

然后你必须在代码中设置Document属性:

Then you have to set the Document property in code:

TestViewer.Document = Application.LoadComponent(
    new Uri("/Resources/FlowDocument1.xaml", UriKind.Relative)) as FlowDocument;

这篇关于如何使用 DocumentViewer 显示流文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆