在ScrollViewer-Silverlight中打印所有内容
我正在ScrollViewer控件中显示大约100条记录。当我打印ScrollViewer控件时,它只打印当前视图(10条记录)。如何一次打印所有100个数据?您可能希望在Silverlight中使用PrintDocument类。 用法是 在XAML文件中创建列表作为在ScrollViewer-Silverlight中打印所有内容,silverlight,silverlight-4.0,Silverlight,Silverlight 4.0,我正在ScrollViewer控件中显示大约100条记录。当我打印ScrollViewer控件时,它只打印当前视图(10条记录)。如何一次打印所有100个数据?您可能希望在Silverlight中使用PrintDocument类。 用法是 在XAML文件中创建列表作为 <ScrollViewer Height="300" VerticalScrollBarVisibility="Auto"> <ItemsControl x:Name="printSur
<ScrollViewer Height="300" VerticalScrollBarVisibility="Auto">
<ItemsControl x:Name="printSurface">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
Height="25">
<TextBlock Width="100"
Text="{Binding Name}" />
<TextBlock Width="75"
Text="{Binding Genre.Name}" />
<TextBlock Width="50"
Text="{Binding Price, StringFormat=c}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
代码隐藏看起来像
void printButton_Click(object sender, RoutedEventArgs e)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += new EventHandler<PrintPageEventArgs>(doc_PrintPage);
doc.Print("Page title");
}
void doc_PrintPage(object sender, PrintPageEventArgs e)
{
// Stretch to the size of the printed page
printSurface.Width = e.PrintableArea.Width;
printSurface.Height = e.PrintableArea.Height;
// Assign the XAML element to be printed
e.PageVisual = printSurface;
// Specify whether to call again for another page
e.HasMorePages = false;
}
void printButton\u单击(对象发送器,路由目标)
{
PrintDocument文档=新的PrintDocument();
doc.PrintPage+=新事件处理程序(doc\u PrintPage);
文件打印(“页面标题”);
}
无效文档\u打印页(对象发送者,打印页事件参数e)
{
//拉伸到打印页面的大小
printSurface.Width=e.PrintableArea.Width;
printSurface.Height=e.PrintableArea.Height;
//指定要打印的XAML元素
e、 PageVisual=打印表面;
//指定是否再次调用另一页
e、 HasMorePages=false;
}
在打印时检查此解决方案