问题描述
我的资源中有一个简单的流文档,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.您可以改用
FlowDocumentScrollViewer
或 FlowDocumentPageViewer
.
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 显示流文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!