Ask a questionAsk a question
 

AnswerCrystal Report Viewer

  • Tuesday, February 26, 2008 6:32 PMdarkforce Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Thursday, February 28, 2008 4:44 AMWei Zhou - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

  • Thursday, February 28, 2008 4:44 AMWei Zhou - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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

  • Thursday, February 28, 2008 5:02 PMJTB_XBAP Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Will this work for an XBAP?
  • Thursday, February 28, 2008 6:29 PMdarkforce Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
     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 Smile
  • Friday, February 29, 2008 6:40 AMWei Zhou - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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