使用自定义打印模板(用户控件)在Silverlight 4中进行多页打印

时间:2010-07-09 18:37:07

标签: silverlight printing silverlight-4.0

在使用自定义打印模板打印多个页面时,我需要一些帮助。打印模板(Silverlight用户控件)由两个文本块(标题和内容,它们显示并稍后打印相应的文本)组成。我遇到的问题是它只能打印1页,如何将其扩展为打印多页。这是工作流程 -

  • 内容(要打印的内容可能非常大)首先显示在子窗口中嵌入的文本块上(自定义消息框的种类)。
  • 需要打印此内容,因此我创建了一个自定义打印模板,该模板将分别打印标题和内容。
  • 现在,我不知道如何扩展它以打印多个页面。

这是我的xaml -

<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="10,10,10,10" >
        <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="10" BorderThickness="5" Background="White" Height="50" >
            <TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="2" TextWrapping="Wrap" Name="TitleTextBlock" FontSize="16" 
                       TextAlignment="Center" FontFamily="Times New Roman" FontStyle="Italic" FontWeight="SemiBold" >
            </TextBlock>
        </Border>
        <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="10" Margin="0,10,0,0" BorderThickness="5" Background="White" Height="950" >
            <TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10" TextWrapping="Wrap" Name="ContentTextBlock" FontSize="14"
                       FontFamily="Times New Roman" FontWeight="Normal" >
            </TextBlock>
        </Border>
</StackPanel>

和我的代码 -

Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    printDoc.Print("MyTest")
End Sub

Private Sub printDoc_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)

    Dim printPage As New PrintingPageTemplate

    'printPage.PageTitle = Me.Title.ToString
    'printPage.PageContent = Me.txtMessage.Text
    printPage.TitleTextBlock.Text = Me.Title.ToString
    printPage.ContentTextBlock.Text = Me.txtMessage.Text 'The txtMessage is a text block which consists of data to be printed and it can have very large content

    e.PageVisual = printPage
    'e.HasMorePages = True ' This doesn't work
End Sub

需要一些逻辑来检查TitleTextBlock的总大小并创建PrintingTemplate的新实例。有人可以请一些指示我如何实现这一目标? (我希望我能够为我的问题提供足够的信息)。

1 个答案:

答案 0 :(得分:0)

我能做的最好的就是做到这一点 - 抛出一些指针!前几天我发现这篇文章并认为在发现Silverlight中的打印远非我想象的那么简单之后它可能会派上用场。

http://www.gal-systems.com/2/post/2011/02/multiple-pages-printing-in-silverlight-4.html

和第二部分,用于生成打印预览:

http://www.gal-systems.com/2/post/2011/02/multiple-page-printing-in-silverlight4-part-2-preview-before-printing.html

告诉我们你是如何上场的!