Crystal Reports - 值不能为空.参数名称:窗口

54

本文介绍了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 - 值不能为空.参数名称:窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14