• North American Sales: 1-800-231-8588
  • Global Contacts
  • My Account
Infragistics Infragistics
Menu
  • North American Sales: 1-800-321-8588
  • My Account
    • Sign In/Register
  • Design & DevelopmentDesign & Develop
    • Best Value
      Infragistics Ultimate The complete toolkit for building high performing web, mobile and desktop apps.
      Indigo.Design Use a unified platform for visual design, UX prototyping, code generation and application development.
    • Web
      Ignite UI for Angular Ignite UI for JavaScript Ignite UI for React Ultimate UI for ASP.NET Indigo.Design
    • Desktop
      Ultimate UI for Windows Forms Ultimate UI for WPF
      Prototyping
      Indigo.Design
    • Mobile
      Ultimate UI for Xamarin Ultimate UI for iOS Ultimate UI for Android
    • Automated Testing Tools
      Test Automation for Micro Focus UFT: Windows Forms Test Automation for Micro Focus UFT: WPF Test Automation for IBM RFT: Windows Forms
  • UX
    • Indigo.Design Desktop Collaborative prototyping and remote usability testing for UX & usability professionals
    • Indigo.Design A Unified Platform for Visual Design, UX Prototyping, Code Generation, and App Development
  • Business Intelligence
    • Reveal Embedded Accelerate your time to market with powerful, beautiful dashboards into your apps
    • Reveal App Empower everyone in your organization to use data to make smarter business decisions
  • Team Productivity
  • Learn & Support Support
    • Help & Support Documents
    • Blogs
    • Forums
    • Product Ideas
    • Reference Applications
    • Customer Stories
    • Webinars
    • eBook & Whitepapers
    • Events
  • Free Trials
  • Pricing
    • Product Pricing / Buy Online
    • Renew Existing License
    • Contact Us
WPF
  • Product Platforms
  • More
WPF
WPF Printing the XamDataGrid with Infragistics.Reports
  • Blog
  • Files
  • Wiki
  • Mentions
  • Tags
  • More
  • Cancel
  • New
WPF requires membership for participation - click to join
  • WPF
  • Configuring the XamTab Control
  • Creating a Custom Summary for the XamDataGrid
  • Defining a Custom Path in the XamCarousel
  • Enabling Row Summaries in the XamDataGrid
  • Exporting the XamDataGrid to Excel
  • Hosting a WPF Control in a Windows Forms Application
  • Printing the XamDataGrid with Infragistics.Reports
  • Spell Checking in the XamDataGrid
  • Tangerine -- A WPF Reference Application
  • Using the Infragistics WinGrid in a WPF Application
  • Validation in the XamDataGrid
  • XamDataGrid :: Copying to Excel via the Clipboard
  • XML Databinding with the XamDataGrid

Printing the XamDataGrid with Infragistics.Reports

Introduction

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.

Setting up Infragistics.Reports

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  
   Infragistics.Windows.Reporting.Report();

Infragistics.Windows.Reporting.EmbeddedVisualReportSection 
myXamDataGridReport = new
Infragistics.Windows.Reporting.EmbeddedVisualReportSection(this.xamDataGrid1);

myReport.Sections.Add(myXamDataGridReport);

Print Preview

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:

<Window x:Class="XamCommunitySample.MainWindow1"
…
        xmlns:igReports="http://infragistics.com/Reporting"
… >
…
    <igReports:XamReportPreview x:Name="xamReportPreview1" />
…
</Window>

C#

//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:

  • Infragistics.Windows.Reports.Report – The Report that the developer wants to print/print preview
  • bool ShowPrintDialog – This shows the standard PrintPreviewDialog that enables the application’s consumer to configure the printer and print location.
  • bool ShowReportProgressControl – this is a helper that will generate a dialog that will give the application’s consumer a status on the status of the print preview being generated.

Printing

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:

myReport.Print();

myReport.Export(Infragistics.Windows.Reporting.OutputFormat.XPS, 
  "FileLocation");

That’s it. With that small amount of code, you have successfully printed or exported your XamDataGrid or any Visual Element.

  • WPF
  • XamDataGrid
  • Infragistics.Reports
  • Share
  • History
  • More
  • Cancel
Related
Recommended