I incorporate CrystalReportsViewer in my WPF app using VS 2015. Here is my View:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:KnoxFactoryLoader.Views"
xmlns:Viewer="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer" ToolTip="Production Batch Report" x:Name="ProductionBatch" x:Class="KnoxFactoryLoader.Views.Report_View"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="Production Batch Report View" Height="600" Width="700">
<Viewer:CrystalReportsViewer Name="rptView" ShowLogo="False" ShowToolbar="True" ShowToggleSidePanelButton="False"
ToggleSidePanel="None" Focusable="True" ShowOpenFileButton="False"
ShowCopyButton="False" ShowRefreshButton="False"
HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Window>
Here is my code behind:
public partial class Report_View : Window
{
public Report_View(string param1, string reportName)
{
CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
reportDocument.Load(reportName);
CrystalDecisions.CrystalReports.Engine.Tables CrTables;
CrystalDecisions.Shared.TableLogOnInfo crtableLogoninfo = new CrystalDecisions.Shared.TableLogOnInfo();
CrystalDecisions.Shared.ConnectionInfo crConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
crConnectionInfo.ServerName = "ServerName1";
crConnectionInfo.DatabaseName = "DatabaseName1";
crConnectionInfo.UserID = "user1";
crConnectionInfo.Password = "pass1";
CrystalDecisions.Shared.TableLogOnInfo crtableLogoninfo2 = new CrystalDecisions.Shared.TableLogOnInfo();
CrystalDecisions.Shared.ConnectionInfo crConnectionInfo2 = new CrystalDecisions.Shared.ConnectionInfo();
crConnectionInfo2.ServerName = "ServerName2";
crConnectionInfo2.DatabaseName = "DatabaseName2";
crConnectionInfo2.UserID = "user2";
crConnectionInfo2.Password = "pass2";
CrTables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
if (CrTable.Name.Equals("TABLE1"))
{
crtableLogoninfo2 = CrTable.LogOnInfo;
crtableLogoninfo2.ConnectionInfo = crConnectionInfo2;
CrTable.ApplyLogOnInfo(crtableLogoninfo2);
}
else
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
}
reportDocument.SetParameterValue("Param1", param1);
InitializeComponent();
rptView.ViewerCore.ReportSource = reportDocument;
var viewer = rptView as SAPBusinessObjects.WPF.Viewer.CrystalReportsViewer;
if (viewer != null)
{
viewer.Focusable = true;
viewer.Focus();
}
}
The report created is correct. However, there are a lot of debug error messages.
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' BindingExpression:Path=ToolTip; DataItem='Button' (Name='btnOpen'); target element is 'Button' (Name='btnOpen'); target property is 'Name' (type 'String') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' BindingExpression:Path=ToolTip; DataItem='Button' (Name='btnPrint'); target element is 'Button' (Name='btnPrint'); target property is 'Name' (type 'String') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' BindingExpression:Path=ToolTip; DataItem='Button' (Name='btnRefresh'); target element is 'Button' (Name='btnRefresh'); target property is 'Name' (type 'String') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' BindingExpression:Path=ToolTip; DataItem='Button' (Name='btnExport'); target element is 'Button' (Name='btnExport'); target property is 'Name' (type 'String') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' BindingExpression:Path=ToolTip; DataItem='Button' (Name='btnCopy'); target element is 'Button' (Name='btnCopy'); target property is 'Name' (type 'String') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' BindingExpression:Path=ToolTip; DataItem='ToggleButton' (Name='btnToggleSidePanel'); target element is 'ToggleButton' (Name='btnToggleSidePanel'); target property is 'Name' (type 'String') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' BindingExpression:Path=ToolTip; DataItem='Button' (Name='btnPrevPage'); target element is 'Button' (Name='btnPrevPage'); target property is 'Name' (type 'String') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' BindingExpression:Path=ToolTip; DataItem='Button' (Name='btnNextPage'); target element is 'Button' (Name='btnNextPage'); target property is 'Name' (type 'String') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' BindingExpression:Path=ToolTip; DataItem='Button' (Name=''); target element is 'Button' (Name=''); target property is 'Name' (type 'String') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='' BindingExpression:Path=ToolTip; DataItem='Button' (Name=''); target element is 'Button' (Name=''); target property is 'Name' (type 'String')
I search SAP website and couldn't find a solution.
Thank you in advance.