xmlns:igDP="http://infragistics.com/DataPresenter"
Before you can preview, print, or export a report, you must instantiate a Report object and add EmbeddedVisualReportSection objects to its Sections collection. After adding sections to the Report object, you can display a print preview of the report using the xamReportPreview™ control, export the report in XML paper specification (XPS), or print the report to a printer.
You will create a report using xamDataGrid™ as the main content.
You will add xamReportPreview to your window.
Create a Microsoft® Windows® Presentation Foundation Window project.
In the Solution Explorer, add the following NuGet package references to your project. For more information on setting up the NuGet feed and adding NuGet packages, you can take a look at the following documentation: NuGet Feeds.
Infragistics.WPF.Reporting
Infragistics.WPF.DataGrids
You only need a reference to the first package in the list above to implement reporting functionality in your application. The XamDataGrid control is going to be used to demonstrate reporting functionality in the rest of this topic.
Add a namespace declaration for XamDataGrid inside the opening Window tag.
In XAML:
xmlns:igDP="http://infragistics.com/DataPresenter"
Add a DockPanel container to the Window.
In XAML:
<DockPanel> <!--TODO: Add a Button here--> <!--TODO: Add xamDataGrid here--> </DockPanel>
Add a Button control to the DockPanel container.
Set the attached DockPanel.Dock property to Top.
Set the Content property to "Print xamDataGrid".
Attach an event handler to the Button control’s Click event.
In XAML:
<Button DockPanel.Dock="Top" Content="Print xamDataGrid" Click="Button_Click" />
Add xamDataGrid to the DockPanel container.
Set the Name property so you can reference it in the code-behind.
Set the BindToSampleData to True.
In XAML:
<igDP:XamDataGrid Name="xamDataGrid1" BindToSampleData="True" />
Open the code-behind and place using/Imports directives in your code-behind so you don’t have to type out a member’s fully qualified name.
In Visual Basic:
Imports Infragistics.Windows.Reporting
In C#:
using Infragistics.Windows.Reporting;
Add an event handler for the Button control’s Click event if a method stub has not been created for you, instantiate a Report and an EmbeddedVisualReportSection object and pass a reference to the xamDataGrid control to its constructor. Finally add the EmbeddedVisualReportSection object to the Report object’s Sections collection and invoke the Report object’s Print or Export method.
In Visual Basic:
Private Sub Button_Click(sender As Object, e As RoutedEventArgs) Dim report1 As New Report() Dim section1 As New EmbeddedVisualReportSection(Me.xamDataGrid1) report1.Sections.Add(section1) report1.Print() 'The following line of code will export 'the contents of xamDataGrid to an XPS document. 'report1.Export(OutputFormat.XPS, "c:\\xamDataGrid1.xps") End Sub
In C#:
private void Button_Click(object sender, RoutedEventArgs e) { Report report1 = new Report(); EmbeddedVisualReportSection section1 = new EmbeddedVisualReportSection(this.xamDataGrid1); report1.Sections.Add(section1); report1.Print(); //The following line of code will export //the contents of xamDataGrid to an XPS document. //report1.Export(OutputFormat.XPS, "c:\\xamDataGrid1.xps"); }
Run the project.
You should see a Window that looks similar to the screen shot below. You can click the button labeled "Print xamDataGrid" to print the contents of the xamDataGrid control.
Create a Microsoft® Windows® Presentation Foundation Window project.
Add the following NuGet package reference to your project:
Infragistics.WPF.Reporting
For more information on setting up the NuGet feed and adding NuGet packages, you can take a look at the following documentation: NuGet Feeds.
Add the Infragistics name space declarations
In XAML:
xmlns:igReporting="http://infragistics.com/Reporting"
In Visual Basic:
Imports Infragistics.Windows.Reporting
In C#:
using Infragistics.Windows.Reporting;
Name the default Grid layout container so you can reference it in the code-behind.
In XAML:
<Grid Name="layoutRoot"> </Grid>
Attach an event handler to the Window’s Loaded event if you are going to use the code-behind.
In XAML:
<Window ... Loaded="Window_Loaded">
Create an instance of xamReportPreview control and add it in the main Grid.
In XAML:
<igReporting:XamReportPreview Name="xamReportPreview1" />
In Visual Basic:
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Dim xamReportPreview1 = New XamReportPreview() Me.layoutRoot.Children.Add(xamReportPreview1) End Sub
In C#:
private void Window_Loaded(object sender, RoutedEventArgs e) { XamReportPreview xamReportPreview1 = new XamReportPreview(); this.layoutRoot.Children.Add(xamReportPreview1); }
Run your project.
When you run the project, you should see a Window that looks similar to the screen shot below. The xamReportPreview control will not display any content since it has not generated a preview of a report. You have to call xamReportPreview’s GeneratePreview method and pass in a reference to a Report object.