WPF FixedDocument背景图片

时间:2015-03-13 00:11:49

标签: c# wpf

在哪里放置FixedDocument的背景图像?我在FlowDocument中看到它,但在FixedDocument中没有。

在FlowDocument中

  <FlowDocument.Background>
    <ImageBrush>
        <ImageBrush.ImageSource>
            <!--Image source here...-->
        </ImageBrush.ImageSource>
    </ImageBrush>
  </FlowDocument.Background>

2 个答案:

答案 0 :(得分:1)

您可以使用以下方式进行操作:

<FixedPage xmlns="http://schemas.microsoft.com/xps/2005/06"
Width="793.60" Height="1122.56" xml:lang="fr">
    <Canvas>
        <Path Data="M 0.00,0.00 L 0.00,3508.00 L 2480.00,3508.00 L 2480.00,0.00 Z">
            <Path.Fill>
                <ImageBrush ImageSource="xxx.jpg"
                            TileMode="None"
                            Viewbox="0,0,3306.67,4677.33"
                            ViewboxUnits="Absolute"
                            Viewport="0.00,0.00,2480.00,3508.00"
                            ViewportUnits="Absolute"/>
            </Path.Fill>
        </Path>
    ...
    </Canvas>

答案 1 :(得分:0)

您应该可以使用FixedPage.Background为每个固定页面逐页设置:

        <DocumentViewer Name="mainRTB" >
            <FixedDocument>
                <FixedDocument.Resources>
                    <ImageBrush x:Key="backgroundImage" TileMode="Tile" Stretch="Fill" Viewport="0,0,1.0,0.33333333" AlignmentX="Center">
                        <ImageBrush.ImageSource>
                            <!--Image source here...-->
                        </ImageBrush.ImageSource>
                    </ImageBrush>
                </FixedDocument.Resources>
                <PageContent>
                    <!-- 7" x 9" page -->
                    <FixedPage Width="672" Height="864" Background="{StaticResource backgroundImage}">
                        <StackPanel Orientation="Vertical" FixedPage.Left="280" FixedPage.Top="150">
                            <Label FontFamily="Arial" FontWeight="Bold" FontSize="18" Content="Jane Eyre" HorizontalAlignment="Center"/>
                            <Label FontFamily="Arial" FontStyle="Italic" FontSize="14" Content="Charlotte Brontë" HorizontalAlignment="Center"/>
                        </StackPanel>
                    </FixedPage>
                </PageContent>
                <PageContent>
                    <FixedPage Width="672" Height="864" Background="{StaticResource backgroundImage}">
                        <StackPanel Margin="48">
                            <TextBlock FontFamily="Cambria" FontSize="14" Width="576" TextWrapping="Wrap">
                There was no possibility etc.
                            </TextBlock>
                            <TextBlock FontFamily="Cambria" FontSize="14" Width="576" TextWrapping="Wrap" Margin="0,25,0,0">
                I was glad of it etc.
                            </TextBlock>
                        </StackPanel>
                    </FixedPage>
                </PageContent>
            </FixedDocument>
        </DocumentViewer>

似乎它也打印出来 - 至少我看到我的背景图像在打印到PDF995时显示出来。