Access SQL Server Report Viewer in WPF

I tried using the report viewer that comes with VS2010 in WPF. I created a report and tested it with the Windows application in which it runs. Then I used the same RDLC file in WPF with the same set of options, but it fails. The code I'm using is below MainWindow.xaml.cs

public MainWindow()
{
   ObjectModel DataObject = new ObjectModel();
   DataObject.SetEPSDetails();
   WindowsFormsHost host = new WindowsFormsHost();
   ReportViewer RptViewer = new ReportViewer();
   host.Child = RptViewer;
   Grid HostGrid = this.FindName("GrdRow") as Grid;
   HostGrid.Children.Add(host);

   RptViewer.ProcessingMode = ProcessingMode.Local;
   RptViewer.LocalReport.ReportEmbeddedResource = "RDLWPF.PrintPreview.rdlc";

   RptViewer.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("Payer", DataObject.Payer));
   RptViewer.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("ValueDate", DataObject.ValueDate));
   RptViewer.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("FileName", DataObject.FileName));
   RptViewer.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("Description", DataObject.Description));
   RptViewer.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("PrintedDate", DataObject.PrintDate));
   RptViewer.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("FileLastUpdated", DataObject.FileLastUpdated));
   RptViewer.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("FileDetails", DataObject.EPSDetails));
   RptViewer.RefreshReport();
}

Xaml is located below Mainwindow.Xaml

<Window x:Class="RDLWPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:viewer="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
        Title="MainWindow" Height="350" Width="525"  AllowsTransparency="False" >
    <Grid x:Name="GrdRow">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>

    </Grid>

I just get an empty XAML window. The report control also does not appear. I know that I am making a mistake, but I can’t find what it is. Is there anyone who can fix this for me. Also, if someone can send me sample code in MVVM evaluation, which would also be great

Thank you and welcome Venkatesh

+5
1

, SQL Report Viewer WPF:

1- WindowsFormsIntegation
2- Microsoft.ReportViewer.Winforms
3- Microsoft.ReportViewer.Common

4- WindowsFormsHost

public MainWindowViewModel()
{
   ReportViewer reportViewer = new ReportViewer();
   _viewer.Child = reportViewer;
}

private WindowsFormsHost _viewer = new WindowsFormsHost();
public WindowsFormsHost Viewer
{
  get
  {
    return _viewer;
  }
  set
  {
    _viewer = value;
    NotifyPropertyChanged("Viewer");
  }
}

4-

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition/>
  </Grid.RowDefinitions>
  <ContentPresenter Grid.Row="0" Content="{Binding Viewer}" />
</Grid>
+5

All Articles