我的资源中有一个简单的流程文档,FlowDocument1.xaml
:
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
ColumnWidth="400" FontSize="14" FontFamily="Georgia">
<Paragraph>
Test
</Paragraph>
</FlowDocument>
我希望在DocumentViewer
中显示此文档。我搜索了一个带路径的房产,但我找不到。以下引发异常:
<DocumentViewer x:Name="TestViewer" Document="Resources/FlowDocument1.xaml" />
如何在FlowDocument1.xaml
中显示DocumentViewer
?
答案 0 :(得分:4)
首先,您无法将FlowDocument
添加到DocumentViewer
,因为它仅支持FixedDocument
。您可以改为使用FlowDocumentScrollViewer
或FlowDocumentPageViewer
。
<FlowDocumentScrollViewer x:Name="TestViewer"/>
然后你必须在代码中设置Document
属性:
TestViewer.Document = Application.LoadComponent(
new Uri("/Resources/FlowDocument1.xaml", UriKind.Relative)) as FlowDocument;
答案 1 :(得分:4)
<Grid>
<Grid.Resources>
<FlowDocument x:Key="YourFlowDoc">
<Paragraph>
<TextBox Text="See it's Easy!"/>
</Paragraph>
</FlowDocument>
</Grid.Resources>
<FlowDocumentReader Document={StaticResource YourFlowDoc}"/>
</Grid>