tags:

views:

1626

answers:

1

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);
    }
   }
  }
 }
+1  A: 

mmkay, so I found the answer myself here :)

This helped me (Anybody an idea what the 'reason' behind is? Bug?)

PS: In a flowdocument, i experience the same issue, and have not been able to resolve it there. Any ideas?

Tom Deleu