I need to print datagrid records only. I used one code like this, but this one printed datagrid scroll bar also. I need only records.
PrintDialog printDlg =
Hey For Print DataGrid in WPF you have to take and use given code.
Xaml Code is
And .CS code is
private void OnDataGridPrinting(object sender, RoutedEventArgs e)
{
System.Windows.Controls.PrintDialog Printdlg = new System.Windows.Controls.PrintDialog();
if ((bool)Printdlg.ShowDialog().GetValueOrDefault())
{
Size pageSize = new Size(Printdlg.PrintableAreaWidth, Printdlg.PrintableAreaHeight);
// sizing of the element.
dataGrid1.Measure(pageSize);
dataGrid1.Arrange(new Rect(5, 5, pageSize.Width, pageSize.Height));
Printdlg.PrintVisual(dataGrid1, Title);
}
}
Hope it helps you
This is tested code.