8,735
社区成员
发帖
与我相关
我的任务
分享
<Style TargetType="layout:QuestionCollectionContainer">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"></StackPanel>
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="layout:QuestionCollectionContainer">
<ScrollViewer Background="LightGray" Height="auto">
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="layout:QuestionPage">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="layout:QuestionPage">
<Grid Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" Margin="0,15,0,0" Background="White" x:Name="PageGrid">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid Margin="{TemplateBinding Margin}" x:Name="PageContentAreaGrid">
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
</Grid.RowDefinitions>
<barcode:Code39 Height="50" x:Name="TopBarCode" HumanText="{TemplateBinding TopBarCodeText}" ShowHumanText="True" Width="300" HorizontalAlignment="Left"></barcode:Code39>
<ItemsPresenter Grid.Row="1" />
<Canvas Grid.Row="2" Height="25" x:Name="PageFooterCanvas" VerticalAlignment="Bottom">
<TextBlock x:Name="PageNumberInforText">
<Run x:Name="PageNumberRun"></Run>
</TextBlock>
<barcode:Code39 x:Name="BottomBarCode" HumanText="{TemplateBinding BottomBarCodeText}" ShowHumanText="False" Width="300" Height="25"></barcode:Code39>
</Canvas>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
private void btnprint_Click(object sender, RoutedEventArgs e)
{
CurrentPage = 0;
PrinterFallbackSettings settings = new PrinterFallbackSettings();
settings.ForceVector = true;
settings.OpacityThreshold = 0.5;
PrintDocument pd = new PrintDocument();
pd.PrintPage += new EventHandler<PrintPageEventArgs>(pd_PrintPage);
pd.Print("test", settings);
}
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
if (CurrentPage < (this.questionCollectionContainer.Items.Count - 1))
{
e.HasMorePages = true;
this.CurrentPage++;
e.PageVisual = (QuestionPage)questionCollectionContainer.Items[CurrentPage - 1];
}
else
{
e.HasMorePages = false;
this.CurrentPage++;
e.PageVisual = (QuestionPage)questionCollectionContainer.Items[CurrentPage - 1];
}
}