title: Crystal Reporting in MVVM pattern and prism lib
body: <p>I've just read this <a href="http://scn.sap.com/thread/2025845" rel="nofollow noreferrer">link</a> and follow the steps.but my crystal report viewer is not posting the report, but doesn't throw any Exception.</p>
  
  <p>How do I fix this?</p>
  
  <p>I've tried it in coding behind the view and it ran smoothly.</p>
  
  <p><strong>VIEWMODEL</strong>  </p>
  
  <pre><code>    using CrystalDecisions.CrystalReports.Engine;
  using FINNANCE_PROGRAM.Views.ReportViewer;
  using Prism.Commands;
  using Prism.Mvvm;
  using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  
  namespace FINNANCE_PROGRAM.ViewModels.ReportViewer
  {
      public class MonthlyTrialBalanceReportViewerViewModel : BindableBase
      {
  
          public DelegateCommand LoadMonthlyReport { get; set; }
  
  
          private ReportDocument _MyReportSource;
          public ReportDocument MyReportSource
          {
              get { return _MyReportSource; }
              set
              {
                  if (_MyReportSource != null)
                  {
                      SetProperty(ref _MyReportSource, value);
                  }
              }
          }
  
  
  
  
  
  
          public MonthlyTrialBalanceReportViewerViewModel()
          {
              LoadMonthlyReport = new DelegateCommand(OpenLoadMonthlyReport);
              MyReportSource = new ReportDocument();
          }
  
  
  
          private void OpenLoadMonthlyReport()
          {
              ReportDocument rpts = new ReportDocument();
             // MonthlyTrialBalanceReportViewer repviewer = new MonthlyTrialBalanceReportViewer();
              rpts.Load(@"E:\TEST_USER\Desktop\FINAL_DECISION_FIN_PROG\2016\FINNANCE_PROGRAM 1-26-2016\FINNANCE_PROGRAM\bin\Debug\ReportDesign\MonthlyTrialBalanceReportDoc.rpt");
              DataTable dt = new DataTable();
              DataRow dr;
  
  
  
              dt.Columns.Add("Dept");
              dt.Columns.Add("Item_No");
              dt.Columns.Add("AccountCode");
              dt.Columns.Add("AccountName");
              dt.Columns.Add("Branch");
              dt.Columns.Add("OpeningBalance");
              dt.Columns.Add("TotalDebit");
              dt.Columns.Add("TotalCredit");
              dt.Columns.Add("EndingBalance");
  
              dr = dt.NewRow();
              dr[0] = "11111";
              dr[1] = "22222";
              dr[2] = "22222";
              dr[3] = "33333";
              dr[4] = "44444";
              dr[5] = "55555";
              dr[6] = "66666";
              dr[7] = "77777";
              dr[8] = "88888";
  
              dt.Rows.Add(dr);
  
              rpts.SetDataSource(dt);
              //repviewer.RepViewer.ViewerCore.ReportSource = rpts;
             MyReportSource = rpts;
          }
      }
  }
  </code></pre>
  
  <p><strong>VIEW (XAML)</strong></p>
  
  <pre><code>&lt;UserControl    x:Class="FINNANCE_PROGRAM.Views.ReportViewer.MonthlyTrialBalanceReportViewer"
               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:prism="http://prismlibrary.com/"
               xmlns:Viewer="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer" 
               xmlns:ReportB="clr-namespace:FINNANCE_PROGRAM.AllReports"
                  prism:ViewModelLocator.AutoWireViewModel="True"
  
               mc:Ignorable="d" 
               d:DesignHeight="500" d:DesignWidth="800"&gt;
      &lt;Grid&gt;
          &lt;Grid.RowDefinitions&gt;
              &lt;RowDefinition Height="10"/&gt;
              &lt;RowDefinition/&gt;
              &lt;RowDefinition Height="10"/&gt;
          &lt;/Grid.RowDefinitions&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition Width="200"/&gt;
              &lt;ColumnDefinition/&gt;
          &lt;/Grid.ColumnDefinitions&gt;
  
  
          &lt;StackPanel Grid.Row="1"&gt;
              &lt;Button  Command="{Binding LoadMonthlyReport}" Content="Load" /&gt;
          &lt;/StackPanel&gt;
  
  
  
  
  
          &lt;Viewer:CrystalReportsViewer Name="RepViewer" ReportB:ReportSourceBehaviour.ReportSource="{Binding Path=MyReportSource, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=FrameworkElement}}"  Grid.Column="1"  Grid.Row="1" /&gt;
  
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>