Hi
I am using a WPF FixedDocument with databinding for a simple invoice report. Works perfect when viewed inside the sofware itsself.
But i want to print a series of invoices in one click. The following code works perfect (quick 'n dirty, just loads an invoice one by one directly inside the viewmodel, for testing purposes) when I choose the XPS writer, bu fails to print correctly when printing to a real printer. I can see nothing of the data bound to the report. All the graphical elements such as lines are there, but no data. (When i print, with the same button, to de xps writer printer, all data is present, and correct...)
Any Ideas?
private void ExecutePrintCommand(object sender, ExecutedRoutedEventArgs args)
{
var invs = args.Parameter as IList<object>;
using (CompuDataContext db = new CompuDataContext())
{
DataLoadOptions dl = new DataLoadOptions();
dl.LoadWith<Invoice>(f => f.Invoicelines);
db.LoadOptions = dl;
ReportViewer viewer = new ReportViewer();
PrintDialog dlg = new PrintDialog();
if (dlg.ShowDialog() == true)
{
PrintQueue q = dlg.PrintQueue;
foreach (var o in invs)
{
InvoiceListDisplay inv = o as InvoiceListDisplay;
Invoice invoice = db.Invoices.Single(f => f.Id == inv.Id);
viewer.DataContext = new InvoicePrintViewModel(invoice);
XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(q);
xpsdw.Write(viewer.Document);
}
}
}
}