Crystal Reports - Value cannot be null. Parameter name: window(Crystal Reports - 值不能为空.参数名称:窗口)
问题描述
我最近在尝试通过对话框将水晶报表表单加载到我的 WPF 应用程序时遇到一个不寻常的错误,该报表将显示为加载几秒钟,然后抛出一个错误,指出值不能为空. 参数名称:window"
I recently came across an unusual error when attempting to load a crystal report form into my WPF application via a dialog, the report would show as loading for a few seconds and then throw an error stating "Value cannot be null. Parameter name: window"
这让我很困惑,据我所知,水晶报表不使用名为 window 的参数.
This confused me, as far as i know, crystal reports doesn't use a parameter named window.
这是我的代码:
带有 CrystalReportsViewer
<Window x:Class="Client.Views.ReportsWindowView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
Title="ReportsWindowView" Height="300" Width="300" Loaded="Window_Loaded">
<Grid>
<my:CrystalReportsViewer ShowOpenFileButton="True" Grid.Column="1" x:Name="ReportView"/>
</Grid>
并从后面的代码中加载报告(为简单起见,我删除了标准的 ConnectionInfo 代码)
and loading the report from code behind (I've removed the standard ConnectionInfo code for simplicity)
cryRpt = new ReportDocument();
cryRpt.Load("report.rpt");
ReportView.ViewerCore.ReportSource = cryRpt;
推荐答案
原来Crystal Reports在尝试显示内部错误时确实使用了一个名为window的参数.
Turns out that Crystal Reports Does indeed use a parameter named window, when it attempts to show an internal error.
CrystalReportsViewer
处理内部错误并尝试显示 MessageBox:
CrystalReportsViewer
handles internal an error and will try to show a MessageBox:
System.Windows.MessageBox.Show(Window owner, String messageBoxText, String caption, MessageBoxButton button, MessageBoxImage icon)
Show方法获取u201CWindow owneru201D参数,CrystalReportsViewer尝试传递Owner属性CrystalReportsViewer.Owner,但是默认情况下owner为null,所以出现这个意外错误.
Show method get u201CWindow owneru201D parameter and CrystalReportsViewer tries pass Owner property CrystalReportsViewer.Owner, however by default owner is null, as such we get this unexpected error.
一个简单的解决方法是在代码隐藏中(即使使用 mvvm),我们只需通过以下代码将所有者设置为当前窗口:
A simple fix for this, is in the codebehind (even when using mvvm) we simply set the owner to the current window via the following code:
ReportView.Owner = Window.GetWindow(this);
在 OnLoaded 事件或类似事件中执行此操作,您会发现现在您会收到一个消息框,其中包含 CrystalReportsViewer
引发的内部错误.
Do this in the OnLoaded Event or similar, and you will find that now you get a messagebox with an internal error thrown by CrystalReportsViewer
.
此解决方案的功劳属于此线程
Credit for this solution belongs to this thread
这篇关于Crystal Reports - 值不能为空.参数名称:窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Crystal Reports - 值不能为空.参数名称:窗口
基础教程推荐
- c# Math.Sqrt 实现 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01