我刚刚阅读了这个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