我剛剛閱讀了這個link並按照steps.but但我的水晶報告查看器不張貼報告,但不拋出任何異常。Crystal MVVM模式和棱鏡庫中的報告
我該如何解決這個問題?
我試過在編碼背後的視圖,它運行平穩。
視圖模型
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;
}
}
}
VIEW(XAML)
<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">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="1">
<Button Command="{Binding LoadMonthlyReport}" Content="Load" />
</StackPanel>
<Viewer:CrystalReportsViewer Name="RepViewer" ReportB:ReportSourceBehaviour.ReportSource="{Binding Path=MyReportSource, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=FrameworkElement}}" Grid.Column="1" Grid.Row="1" />
</Grid>
</UserControl>
我有這個問題,但已與另一報表組件,我認爲這是問題線程安全,看看線程安全,美好的一天 – toumir
嗨,先生toumir,它解決你的問題?感謝您的回覆 – Neil
是的,我們已經解決了問題,我不記得問題是如何解決的,但它解決了。我的評論爲你提供了一個可以幫助你的想法。 – toumir