Crystal Reports-值不能为null。参数名称:窗口 [英] Crystal Reports - Value cannot be null. Parameter name: window

查看:88
本文介绍了Crystal Reports-值不能为null。参数名称:窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在尝试通过对话框将Crystal报表表单加载到WPF应用程序时遇到一个异常错误,该报表将显示为正在加载几秒钟,然后引发错误,指出 值不能为空参数名称:window



这让我感到困惑,据我所知,Crystal报表未使用名为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-命名空间: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代码)

  cryRpt = new ReportDocument(); 
cryRpt.Load( report.rpt);
ReportView.ViewerCore.ReportSource = cryRpt;


解决方案

结果表明Crystal Reports确实使用名为



CrystalReportsViewer 处理内部错误,并尝试显示一个内部错误。 MessageBox:



System.Windows.MessageBox.Show(窗口所有者,字符串messageBoxText,字符串标题,MessageBoxButton按钮,MessageBoxImage图标)



显示方法get u201CWindow owneru201D参数,CrystalReportsViewer尝试传递Owner属性CrystalReportsViewer.Owner,但是默认情况下owner为null,因此会出现此意外错误。 / p>

一个简单的解决方法是在代码隐藏中(即使使用mvvm时),我们也可以通过以下代码将所有者设置为当前窗口:

  ReportView.Owner = Window.GetWindow(this); 

在OnLoaded事件中执行此操作或类似操作,您会发现现在出现一个带有 CrystalReportsViewer 引发的内部错误。



此解决方案的信用属于此线程


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"

This confused me, as far as i know, crystal reports doesn't use a parameter named window.

This was my code:

A simple window with a 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>

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;

解决方案

Turns out that Crystal Reports Does indeed use a parameter named window, when it attempts to show an internal error.

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 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.

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);

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆