Kailash's Blogs

Use Crystal Report in WPF

Kailash Chandra Behera | Friday, April 06, 2018
Kailash's Blogs


By defult the crystal report software is not part of wpf controls, this following blog guides and provides code snip to use crystals report for WPF in C#.

Use Crystal Report in WPF

Use Crystal Report in WPF

Getting Started

Let’s say you have already developed crystals report(rpt file) using rpt file viewer like above given Image and you want use it in your WPF application for rpt viewer at runtime.

Earlier the crystals report was directly supported in win form and Asp.Net and the rpt viewer were listed in the toolbox, but In WPF you will not get it in the toolbox you need to manually add crystal rpt viewer in XAML by using the namespace.

The behind code is almost the same as the windows used or ASP.Net. Here we will see the both CSharp code and XAML code to use crystal report, see the below code to use crystal report.

XAML Code Snip: For Crystals Report Viewer

 <Window x:Class="CrystalReportDemo.MainWindow"  
     Title="MainWindow" Height="350" Width="525">  
       <RowDefinition Height="30"/>  
       <RowDefinition Height="*"/>  
     <Button Content="View Report" HorizontalAlignment="Left" Margin="5,5,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>  
     <CR:CrystalReportsViewer Grid.Row="1" Name="irRapportViewer" ToggleSidePanel="None" Margin="0,35,0,0"></CR:CrystalReportsViewer>  

C# Code Snip: Loading Crystal Report

 using CrystalDecisions.CrystalReports.Engine;  
 using CrystalDecisions.Shared;  
 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 using System.Threading.Tasks;  
 using System.Windows;  
 using System.Windows.Controls;  
 using System.Windows.Data;  
 using System.Windows.Documents;  
 using System.Windows.Input;  
 using System.Windows.Media;  
 using System.Windows.Media.Imaging;  
 using System.Windows.Navigation;  
 using System.Windows.Shapes;  
 namespace CrystalReportDemo  
   /// <summary>  
   /// Interaction logic for MainWindow.xaml  
   /// </summary>  
   public partial class MainWindow : Window  
     public MainWindow()  
     private void Button_Click(object sender, RoutedEventArgs e)  
       ParameterFields paramFields = new ParameterFields();  
       ParameterField pfItemYr = new ParameterField();  
       pfItemYr.ParameterFieldName = "@No";  
       ParameterDiscreteValue dcItemYr = new ParameterDiscreteValue();  
       dcItemYr.Value = 1;  
       ReportDocument rptDoc = new ReportDocument();  
       rptDoc.SetDatabaseLogon("UserName", "Password", "SQL Server Name", "Database Name"); 
       irRapportViewer.ViewerCore.ReportSource = rptDoc;  
       irRapportViewer.ViewerCore.ParameterFieldInfo = paramFields;
Both codes described how to place report viewer in XAML and load rpt file using behind code. The below steps to provides a complete guideline use crystal report in WPF. The steps are very simple, just follow the below steps.

Steps To Use Crystals Report In WPF.

  1. Download crystal report library(crystal reports download) and take reference of the DLL in your project.
  2. Open your WPF application where you want to implement crystal report.
  3. Just testing purpose add a new Windows control to you project and name it "testingcrystals".
  4. Open the testingcrystals.xaml file and take reference of CrystalDecisions.Shared namespace like below.
  5. Then copy the XAML from to and replace with the grid control in the testingcrystals.xaml file.
  6. Copy the button event from the above C# code snippet and paste it in your testingcrystals.xaml.cs file. change the code as per your requirement.
  7. if you are facing any kind of problem, visit this site for reference of crystal report .
  8. Take reference of below listed DLLs , you will find these DLLs from this path : C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet
    1. SAPBusinessObjects.WPF.Viewer.dll
    2. SAPBusinessObjects.WPF.ViewerShared.dll
    3. System.Windows.Controls.DataVisualization.Toolkit.dll
  9. Now you are done with implementation of crystals report in C# WPF application.


In the above of this article, we say how to implement the crystals report in C# WPF application. I hope you have enjoyed it a log.