4

I have a wpf application. Upon a user request I create a datagrid of certain columns for all the data from a database. I need to print this information. Preferably I would like to print all odd pages first and then all even pages with a header and footer. I have the following code so far but when I print I only get what I see on the screen. I am sure it is pdPrintDialog.PrintVisual statement. I am assuming I need to use pdPrintDialog.PrintDocument. But I don't know to convert the datagrid or datagrid.itemssource to Documents.DocumentPaginator. I can not find how to do this anywhere. Please help!

System.Windows.Controls.PrintDialog pdPrintDialog = new System.Windows.Controls.PrintDialog();

 if ((bool)pdPrintDialog.ShowDialog().GetValueOrDefault())
 {
     Size pntPageSize = new Size(pdPrintDialog.PrintableAreaWidth, pdPrintDialog.PrintableAreaHeight);
     dgPWLCGrid.Measure(pntPageSize);
     dgPWLCGrid.Arrange(new Rect(5, 5, pntPageSize.Width, pntPageSize.Height));
     pdPrintDialog.PrintVisual(dgPWLCGrid, "North Berwick Food Pantry Client Info");
 }
Dazzler
  • 380
  • 3
  • 27
Cass
  • 537
  • 1
  • 7
  • 24
  • Possibly this can help you http://stackoverflow.com/questions/16537126/print-datagrid-records-in-wpf – Dazzler Aug 07 '16 at 23:25
  • #Dazzler - I am already using the c# code. How does the xaml code help the c# code to print the whole data in the datagrid? Is it the binding process? I don't see code to show how itemssource = "{Binding}" works. – Cass Aug 08 '16 at 00:30
  • Can anyone please give me an example or answer my question to #Dazzler? – Cass Aug 10 '16 at 00:42

0 Answers0