Infragistics.Reports is an extremely versatile and powerful code library included in the NetAdvantage for WPF product. Initially, it was created to enable developers an easy mechanism for printing the XamDataGrid or exporting it to XPS. As the control API took shape, new capabilities emerged granting the developer the ability to customize the document by adding header/footers or custom graphics. As we looked at ways for how to push stuff to the printer, it became apparent that we could just print the entire window or place basically any visual element out to the printer. This gives the ability to push the chart or images or whatever you want out. Then some helper controls were added to the library, things to help with the full document printing/exporting experience such as a Print Preview control. This article demonstrates the usage of printing the XamDataGrid and associating a report to the printer.
The first thing that you have to do is add a reference to the Infragistics3.Wpf.Reporting dll. This holds all the critical pieces to write out to the printer/XPS document. Then you need to new up a Report class. This is the piece that is going to be printed. A report consists of a collection of sections. Each of these sections can hold some type of content. A key class that will be most useful is the Infragistics.Windows.Reports.EmbeddedVisualReportSection as this will easily map any visual element to a section.
Infragistics.Windows.Reporting.Report myReport = new
myXamDataGridReport = new
The next thing that you can do is to actually send your printed document to a print preview dialog. Infragistics has created a control (XamReportPreview) to accomplish this. To use it, you can add the control to your WPF Application like this:
<igReports:XamReportPreview x:Name="xamReportPreview1" />
//Method Signature GeneratePreview(Report, bool showPrintDialog, bool showReportProgressControl);
xamReportPreview1.GeneratePreview(myReport, false, true);
You can notice that we are using the xamReportPreview control’s GeneratePreview method and passing it the Report we just created. The method signature actually has a couple extra parameters that will help with the actual experience of the printing experience. The parameters are as follows:
Lastly, there are two other methods that are core to the printing of a document; Export and Print. These two methods do essentially exactly what they describe send a document to the printer or export a document to XPS. The code do to do this looks something like this:
That’s it. With that small amount of code, you have successfully printed or exported your XamDataGrid or any Visual Element.