Crystal Report Viewer
- is ther any Crystal Rerport control in WPF like what we have in Windows Form previously?
I could not locate the any crystal report control in VS 2008...
If not, how can we integrate the reporting services provided by Crystal Report into WPF-application?
Thank you.
Answers
CrystalReportViewer is a Windows Forms control, you can use WPF/Windows Form interop technology to integrate the viewer into the WPF application. Here is the steps you can do.
1. Add a reference to the CrystalDecisions.Windows.Forms.dll.
2. Add a namespace mapping in XAML.
3. Use WindowsFormsHost to host the CrystalReportViewer control.
Sample code:
Code Snippet<Window
x:Class="ForumProjects.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:crystal="clr-namespace:CrystalDecisions.Windows.Forms;assembly=CrystalDecisions.Windows.Forms"
Title="MainWindow" Width="800" Height="600">
<WindowsFormsHost>
<crystal:CrystalReportViewer x:Name="MyCrystalReportViewer" Width="300" Height="300"/>
</WindowsFormsHost>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// reference CrystalReportViewer in code behind
this.MyCrystalReportViewer.BackColor = System.Drawing.Color.AliceBlue;
}
}
Best Regards,
Wei Zhou
All Replies
CrystalReportViewer is a Windows Forms control, you can use WPF/Windows Form interop technology to integrate the viewer into the WPF application. Here is the steps you can do.
1. Add a reference to the CrystalDecisions.Windows.Forms.dll.
2. Add a namespace mapping in XAML.
3. Use WindowsFormsHost to host the CrystalReportViewer control.
Sample code:
Code Snippet<Window
x:Class="ForumProjects.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:crystal="clr-namespace:CrystalDecisions.Windows.Forms;assembly=CrystalDecisions.Windows.Forms"
Title="MainWindow" Width="800" Height="600">
<WindowsFormsHost>
<crystal:CrystalReportViewer x:Name="MyCrystalReportViewer" Width="300" Height="300"/>
</WindowsFormsHost>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// reference CrystalReportViewer in code behind
this.MyCrystalReportViewer.BackColor = System.Drawing.Color.AliceBlue;
}
}
Best Regards,
Wei Zhou
Will this work for an XBAP?Wei Zhou - MSFT wrote: CrystalReportViewer is a Windows Forms control, you can use WPF/Windows Form interop technology to integrate the viewer into the WPF application. Here is the steps you can do.
1. Add a reference to the CrystalDecisions.Windows.Forms.dll.
2. Add a namespace mapping in XAML.
3. Use WindowsFormsHost to host the CrystalReportViewer control.
Sample code:
Code Snippet<Window
x:Class="ForumProjects.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:crystal="clr-namespace:CrystalDecisions.Windows.Forms;assembly=CrystalDecisions.Windows.Forms"
Title="MainWindow" Width="800" Height="600">
<WindowsFormsHost>
<crystal:CrystalReportViewer x:Name="MyCrystalReportViewer" Width="300" Height="300"/>
</WindowsFormsHost>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// reference CrystalReportViewer in code behind
this.MyCrystalReportViewer.BackColor = System.Drawing.Color.AliceBlue;
}
}
Best Regards,
Wei Zhou
Thanks for your reply, will try it out later
If your XBAP is running in a partial trust environment, you were unable to get this work. Otherwise, if your XBAP is running in a full trust environment, you can get this work. By default, XBAP is running in partial trust environment. The reason of this issue is that the CrystalReportViewer is a Windows Forms control and Windows Forms control needs full trust security environment. You can refer to the following link to get more information about XBAP security topic.
http://msdn2.microsoft.com/en-us/library/aa970910.aspx
Best Regards,
Wei Zhou


