//Print DataGrid public void Print_DataGrid(DataGrid dataGrid, string title) { PrintDialog Printdlg = new PrintDialog(); if ((bool)Printdlg.ShowDialog().GetValueOrDefault()) { Size pageSize = new Size(Printdlg.PrintableAreaWidth, Printdlg.PrintableAreaHeight); // sizing of the element. dataGrid.Measure(pageSize); dataGrid.Arrange(new Rect(5, 5, pageSize.Width, pageSize.Height)); Printdlg.PrintVisual(dataGrid, title); } }
public static void PrintDataGrid(DataGrid dataGrid, string title) { var printDialog = new PrintDialog(); if (printDialog.ShowDialog().Value) { var pagesize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight); dataGrid.Measure(pagesize); dataGrid.Arrange(new Rect(5, 5, pagesize.Width, pagesize.Height)); printDialog.PrintVisual(dataGrid, title); } }
public void PrintCardsDirectly(object cards) { // Create a PrintDialog PrintDialog printDlg = new PrintDialog(); //casts the object cards to DataGrid DataGrid dg = cards as DataGrid; // sets Font Size dg.FontSize = fontSize; //prepares a formatted page FormatPrintDialoge(printDlg); //centering the DataGrid to the page Size pageSize = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight + 300); dg.Arrange(new Rect(15, 15, pageSize.Height, pageSize.Width)); // Call PrintDocument method to send document to printer printDlg.PrintVisual(dg, "GridPrinting"); }