Skip to Content
0
Oct 07, 2020 at 04:54 PM

Application closes after Crystal Report Viewer Print dialog is Canceled

280 Views

Hello, I'm developing c# wpf, with crystal report viewer.

the problem is, when I open a new window with crystal report viewer, and click the print button,

then, the main window ( I mean application itself ) is closed. I think this is a bug on viewer side.

Why the entire application is closed when I just cancel the print popup in CrystalReportViewer?

Below is the xaml file.

<res:defaultWnd
xmlns:res="clr-namespace:Universe.Views"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Viewer="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
x:Class="Universe.ReportTemplate.ReportView"
mc:Ignorable="d"
DataContext="{StaticResource MainViewModel}"
Title="Print Report" Width="1400" Height="768">

<Grid Margin="0,0,0,0">
<Viewer:CrystalReportsViewer x:Name="CrystalReportsViewer" HorizontalAlignment="Left" Height="738" VerticalAlignment="Top" Width="1400" />
</Grid>
</res:defaultWnd>

Below is the cs file.

public ReportView()
{
InitializeComponent();
CrystalReportsViewer.Owner = this;
}


internal void draw(DataViewInfo selectedData)
{
DataSet ds = new DataSet("DataSet1");
DataTable dt = new DataTable("DataTable1");
ds.Tables.Add(dt);
//.... populate data table with selectedData ....//

CrystalDecisions.CrystalReports.Engine.ReportDocument report = new MyCrystalReport();
report.SetDataSource(ds);
CrystalReportsViewer.ViewerCore.ReportSource = report;

}