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");
}