2

我的资源中有一个简单的流程文档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

4

2 回答 2

5

首先,您不能将 a 添加FlowDocument到 a DocumentViewer,因为它仅支持FixedDocument. 您可以使用FlowDocumentScrollViewerorFlowDocumentPageViewer代替。

<FlowDocumentScrollViewer x:Name="TestViewer"/>

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

TestViewer.Document = Application.LoadComponent(
    new Uri("/Resources/FlowDocument1.xaml", UriKind.Relative)) as FlowDocument;
于 2013-08-01T14:15:23.613 回答
5
<Grid>
    <Grid.Resources>
        <FlowDocument x:Key="YourFlowDoc">
            <Paragraph>
                <TextBox Text="See it's Easy!"/>
            </Paragraph>
        </FlowDocument>
    </Grid.Resources>
    <FlowDocumentReader Document="{StaticResource YourFlowDoc}" />
</Grid>
于 2014-02-25T06:49:23.407 回答