Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member183750
Active Contributor
0 Kudos

This blog is written to address KB 1544651  - Crystal Reports WPF Viewer fails with NullReferenceException when used in a WinForms a... and the forum post The WPF CrystalReportsViewer fails with NullReferenceException in WinForms. The issue discussed is "fixed", however the fix has not been tested and thus is "not supported". E.g.; we will help you, but in the end your solution may not work.   


Getting it done


    First thing we need is to ensure that the latest update is applied. See SAP Crystal Reports, developer version for Microsoft Visual Studio: Updates & Runtime Downloads for links to all upates. Next, start new Winform project. Mine is a VB project called myWinWPFViewer2. Set your project to use the Full 4.0framework.





Add a reference to "WindowsFormsIntegration". Add a reference to reference to "System.Xaml". Or, if you just place the element control on the form, then these references should be added automatically. If your control is already written, you can add it through the Add Existing Item menu option. If you do not have a control already written, create a new WPF user control that you want to add to your app: Right click on the project name in the Solution Explorer Choose Add | New Item From the Installed Templates, under "Common Items", select WPF | User Control(WPF) Give your control a name if you wish.



"WPFCRControl" Click the Add button




I called mine Your project should now look something like this:We now need to add the Crystal Reports WPF Viewer to the Toolbox In the Toolbox, right click on any white empty space and select "Choose Items..." In the Choose Toolbox Items dialog, click on the WPF Component tab. Select CrystalReportsViewer:




Build your solution now. This will ensure that the WPFCRControl is added and available from the ElementHost below. Go to the Windows form From the Toolbox select Element Host under the WPF Interoperability header, click on the down arrow on the upper right of the ElementHost and select WPFCRontrol

:




Go to the WPFCRControl.xaml form From the Toolbox, select the CrystalReportViewer. The Viewer will now be placed on the Control. Go to the Viewer properties and enable the ShowOpenFileButton:




Run your app, click on the Open File Button on the WPF viewer and browse to a "Saved Data" report. You should now see the report in the viewer: