Version

Printing xamPivotGrid

Topic Overview

Purpose

This topic explains how to print the xamPivotGrid™ .

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic demonstrates how to get started with the xamPivotGrid control by providing step-by-step procedure for adding this control to a WPF application. Code examples include listings in XAML as well as procedural code.

This topic demonstrates how to generate and print a report.

This topic demonstrates how to use the xamReportPreview™ control to display a print preview of a report to your end users.

In this topic

This topic contains the following sections:

Printing xamPivotGrid

Introduction

Using the WPF Reporting framework, the xamPivotGrid can be printed or exported to an XPS document. The following procedure explains how to export to an XPS file or print a pivot grid.

Prerequisites

To complete the procedure, you need the following:

Overview

Following is a conceptual overview of the process:

1. Add the report preview control.

2. Create a new report.

3. Add a section for the xamPivotGrid.

4. Apply a theme to the pivot grid report (optional).

5. Configure the report settings (optional).

6. Generate the preview.

7. Print/Export the report.

Steps

The following steps demonstrate how to generate a print preview and how to print the xamPivotGrid.

1. Add the report preview control

Add the xamReportPreview control to your page. Set its x:Name property to make it accessible from code-behind.

In XAML:

<igRep:XamReportPreview xmlns:igRep="http://infragistics.com/Reporting" x:Name="xamReportPreview" />

2. Create a new report.

In code-behind, create a new Report instance.

In C#:

var report = new Report();

In Visual Basic:

Dim report = New Report()

3. Add a section for the xamPivotGrid.

A report can have multiple Sections. Create a new EmbeddedVisualReportSection, supplying the xamPivotGrid instance as the argument of the constructor. Add the section to the report.

In C#:

var section = new EmbeddedVisualReportSection(this.xamPivotGrid);
report.Sections.Add(section);

In Visual Basic:

Dim section = New EmbeddedVisualReportSection(Me.xamPivotGrid)
report.Sections.Add(section)

4. Apply a theme to the pivot grid report (optional).

Any xamPivotGrid theme added to the application’s resources, is automatically applied to the printed pivot grid. If no theme is added to the application’s resources, or it is added to another ResourceDictionary in one of the application’s visual elements, then the theme must be explicitly added to the resources of the pivot grid report section.

A simplified print-friendly theme is available for the xamPivotGrid report. It can be found in the Themes folder under the product installation path.

To load the printing theme, create a new ResourceDictionary and add it to the section’s Resources. This example assumes that the XamPivotGrid.Printing.xaml file is included in your project in a folder named Themes and its build action is set to Page .

In C#:

var printingTheme = new ResourceDictionary() {
    Source = new Uri("/AssemblyName;component/Themes/XamPivotGrid.Printing.xaml", UriKind.RelativeOrAbsolute) };
section.Resources.MergedDictionaries.Add(printingTheme);

In Visual Basic:

Dim printingTheme = New ResourceDictionary() With { _
      .Source = New Uri("/AssemblyName;component/Folder/XamPivotGrid.Printing.xaml", UriKind.RelativeOrAbsolute) _
}
section.Resources.MergedDictionaries.Add(printingTheme)

5. Configure the report settings (optional).

Report settings can be configured at two levels – through the ReportSettings property of the Report and through the ReportSettings property of the XamPivotGrid.

The report-level settings provide general options such as page size, page orientation, page print order, etc.

The PivotReportSettings allow multiple configurations specific to the printed pivot grid. These include but are not limited to settings for controlling whether custom templates are printed, should the column headers be repeated on every page, etc.

The following example demonstrates how to configure some of the aforementioned settings.

In C#:

report.ReportSettings.HorizontalPaginationMode = HorizontalPaginationMode.Mosaic;
this.xamPivotGrid.ReportSettings.ColumnHeaderCellSettings.RepeatHeaders = true;
this.xamPivotGrid.ReportSettings.RowHeaderCellSettings.RepeatHeaders = false;

In Visual Basic:

report.ReportSettings.HorizontalPaginationMode = HorizontalPaginationMode.Mosaic
Me.pivotGrid.ReportSettings.ColumnHeaderCellSettings.RepeatHeaders = True
Me.pivotGrid.ReportSettings.RowHeaderCellSettings.RepeatHeaders = False

6. Generate the preview.

To generate a preview of the report, call the GeneratePreview method of the XamReportPreview.

In C#:

this.xamReportPreview.GeneratePreview(report, false, false);

In Visual Basic:

Me.xamReportPreview.GeneratePreview(report, False, False)

7. Print/Export the report.

In order to export the report to an XPS document, call the Export method. Alternatively call the Print method to print the report.

In C#:

report.Export(OutputFormat.XPS, "PivotReport", true);
// or
report.Print(true, false);

In Visual Basic:

report.Export(OutputFormat.XPS, "PivotReport", True)
'or
report.Print(True, False)

Full code

Following is the full code for this procedure.

In XAML:

<igRep:XamReportPreview xmlns:igRep="http://infragistics.com/Reporting" x:Name="xamReportPreview" />

In C#:

var report = new Report();
var section = new EmbeddedVisualReportSection(this.xamPivotGrid);
report.Sections.Add(section);
var printingTheme = new ResourceDictionary()
{
    Source = new Uri("/AssemblyName;component/Folder/XamPivotGrid.Printing.xaml", UriKind.RelativeOrAbsolute)
};
section.Resources.MergedDictionaries.Add(printingTheme);
report.ReportSettings.HorizontalPaginationMode = HorizontalPaginationMode.Mosaic;
this.pivotGrid.ReportSettings.ColumnHeaderCellSettings.RepeatHeaders = true;
this.pivotGrid.ReportSettings.RowHeaderCellSettings.RepeatHeaders = false;
this.xamReportPreview.GeneratePreview(report, false, false);
report.Export(OutputFormat.XPS, "PivotReport", true);
report.Print(true, false);

In Visual Basic:

Dim report = New Report()
Dim section = New EmbeddedVisualReportSection(Me.xamPivotGrid)
report.Sections.Add(section)
Dim printingTheme = New ResourceDictionary() With { _
       .Source = New Uri("/AssemblyName;component/Folder/XamPivotGrid.Printing.xaml", UriKind.RelativeOrAbsolute) _
}
section.Resources.MergedDictionaries.Add(printingTheme)
report.ReportSettings.HorizontalPaginationMode = HorizontalPaginationMode.Mosaic
Me.pivotGrid.ReportSettings.ColumnHeaderCellSettings.RepeatHeaders = True
Me.pivotGrid.ReportSettings.RowHeaderCellSettings.RepeatHeaders = False
Me.xamReportPreview.GeneratePreview(report, False, False)
report.Export(OutputFormat.XPS, "PivotReport", True)
report.Print(True, False)

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

The topics in this group explain how to configure and use the individual features of xamPivotGrid .