【发布时间】:2011-03-14 00:48:43
【问题描述】:
我需要一些关于使用自定义打印模板打印多页的帮助。打印模板(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 的新实例。有人可以就我如何实现这一点提出一些指示吗? (我希望我能够为我的问题提供足够的信息)。
【问题讨论】:
标签: silverlight printing silverlight-4.0