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

Crystal Reports - Value cannot be null. Parameter name: window(Crystal Reports - 值不能为空.参数名称:窗口)

本文介绍了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 - 值不能为空.参数名称:窗口

基础教程推荐