我想按照商品打印超级市场账单之类的冗长账单 我使用xps文档,但它们仅打印在xps文档的一页上显示的10种产品
我尝试了下面提到的代码
这是我的用户控件
<UserControl x:Class="BillingSystem.Views.forPrinting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BillingSystem.Views"
mc:Ignorable="d"
d:DesignWidth="1000">
<UserControl.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="35"/>
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</UserControl.Resources>
<ScrollViewer>
<StackPanel>
<TextBlock HorizontalAlignment="Center" FontFamily="times" Text="افضل سویٹس غلہ منڈی دینہ"/>
<TextBlock HorizontalAlignment="Center" FontFamily="times" Text="PH:0544-631031"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1.8*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Customer:" Grid.Column="0"/>
<TextBlock x:Name="tb" Grid.Column="1"/>
<TextBlock Text="Bill No:" Grid.Column="2"/>
<TextBlock x:Name="bill" Grid.Column="3"/>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2.5*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Items:" Grid.Column="0"/>
<TextBlock x:Name="totalitems" Grid.Column="1"/>
<TextBlock Text="Date:" Grid.Column="2"/>
<TextBlock x:Name="date" Grid.Column="3"/>
</Grid>
<DataGrid x:Name="dg" GridLinesVisibility="Horizontal" MinColumnWidth="140" FontWeight="Bold" FontSize="35" BorderBrush="Gray" AreRowDetailsFrozen="True" CanUserReorderColumns="False" BorderThickness="2" IsReadOnly="True"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="Total" FontWeight="Bold" Grid.Column="0"/>
<TextBlock x:Name="total" Grid.Column="1"/>
</Grid>
<TextBlock Text="Thanku for your Visit" HorizontalAlignment="Center"/>
</StackPanel>
</ScrollViewer>
这是我用于打印此用户控件的代码
forPrinting fp = new forPrinting();
// Configure save file dialog box
SaveFileDialog dlg = new SaveFileDialog();
dlg.FileName = txtBill.Text; // Default file name
dlg.DefaultExt = ".xps"; // Default file extension
dlg.Filter = "XPS Documents (.xps)|*.xps"; // Filter files by extension
dlg.InitialDirectory = @"D:\Bills";
/*
if (File.Exists(dlg.FileName))
{
File.Delete(dlg.FileName);
}*/
// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
// Save document
string filename = dlg.FileName;
//FixedDocument doc = (FixedDocument)fp.Document;
XpsDocument xpsd = new XpsDocument(filename, FileAccess.ReadWrite);
XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
xw.Write(fp);
xpsd.Close();
}
//Print
PrintDialog printDlg = new PrintDialog();
printDlg.ShowDialog();
printDlg.PrintVisual(fp, "Grid Printing.");
我想根据产品的不同来打印像超级市场打印账单一样的账单,可以是0-100,因此账单也要打印