C# 指定的Visual已是另一个Visual的子级或组件目标的根
大家好,我一直在使用WPF C#搜索一份报告,找到了一份很好的报告,也很简单,找到了这个并使用它。所以我试着使用它,请检查我的代码 在我的C# 指定的Visual已是另一个Visual的子级或组件目标的根,c#,wpf,C#,Wpf,大家好,我一直在使用WPF C#搜索一份报告,找到了一份很好的报告,也很简单,找到了这个并使用它。所以我试着使用它,请检查我的代码 在我的EmployeeProfileWindowin print按钮中 private void btnprintviolation_Click(object sender, RoutedEventArgs e) { ReportViolationWindow NewReportViolationWindow = new ReportViolationWin
EmployeeProfileWindow
in print按钮中
private void btnprintviolation_Click(object sender, RoutedEventArgs e)
{
ReportViolationWindow NewReportViolationWindow = new ReportViolationWindow();
//Windows.Add(NewReportViolationWindow);
GlobalVar.ViolationEmpNum = txtdispid.Text;
GlobalVar.ViolationRefNumToPrint.Clear();
for (int i = 0; i < lvviolations.Items.Count; i++)
{
GlobalVar.ViolationRefNumToPrint.Add(((EmpViolationObject)lvviolations.Items[i]).VioRefNum);
}
NewReportViolationWindow.Show();
}
现在,当我运行应用程序并单击“打印”按钮时。有时一开始它会打开NewReportViolationWindow
,没有错误,但当我尝试关闭报告或再次单击按钮时,它会给出一条消息
指定的Visual已是另一个Visual的子级或组件目标的根
这是错误的图像
我想问题是当我调用打印按钮后面的代码的打印报告时,嗯,有人可以吗?请……:)
第二次编辑
关于你的问题:
- 您说报告窗口通常打开时不会出现错误 第一次,但不是之后
- 是否有任何共享资源正在使用中
报告违规窗口
- 你是如何处理/处理这场比赛的结束
报告违规窗口
ReportViolationWindow
的代码。当我点击“关闭”按钮时,就这样了,很抱歉:(
- 您是否保留了对该
实例ReportViolationWindow
removelogicchild
或removevisicalchild
(或者理想情况下,从原始ItemsSource中删除项本身并将其添加到新的ItemsSource中)
编辑:从技术上讲,第一段是正确的,但我认为第二段不适用于您……在浏览了上的ReportPaginator
类的源代码后,我注意到以下几点:
- 最新的版本与你的不同,我相信:行不太匹配。这可能是一个已经修复的错误
- (吹毛求疵)我不喜欢这段代码的结构(即报告引擎)…ArrayList?单行if/else/return语句?啊
- 您说报告窗口通常在第一次打开时不会出错,但在那之后就不会了
中是否有正在使用的共享资源ReportViolationWindow
- 您如何处理关闭
ReportViolationWindow
- 您是否保留对该
实例的任何其他引用ReportViolationWindow
EmployeeProfileWindow
)中声明一个类型为NewReportViolationWindow
的单成员变量,而不是:
private void btnprintviolation_Click(object sender, RoutedEventArgs e)
{
ReportViolationWindow NewReportViolationWindow = new ReportViolationWindow();
尝试以下方法:
ReportViolationWindow _reportViolationWindow;
private void btnprintviolation_Click(object sender, RoutedEventArgs e)
{
if(_reportViolationWindow != null)
{
_reportViolationWindow.Close();
_reportViolationWindow = null;
}
_reportViolationWindow = new ReportViolationWindow();
好的,我可能有一个解决方案。如果我将上面的第二个代码段更改为 代码块
ContainerVisual smallerPage = new ContainerVisual( );
DrawingVisual pageVisual = page.Visual as DrawingVisual;
if ( pageVisual != null && pageVisual.Parent != null )
{
ContainerVisual parent = pageVisual.Parent as ContainerVisual;
parent.Children.Remove( pageVisual );
}
smallerPage.Children.Add( page.Visual );
它似乎有效。请评论。我很想知道是否有更好的方法。这似乎是一个黑客行为。你如何给我一个例子,我该怎么做?谢谢…我很抱歉,很可能这不是你的任何代码-我现在只是在查找
ReportPaginator
类的源代码…在这种情况下,很可能您正在处理报告引擎本身的一个bug;因为它是开源的,我建议您获取源代码并调试到代码中…或者询问创建者。hi@JerKimball请检查我对您问题的回答…也许您可以给我除此之外的任何最好的reportviewer…非常感谢您的时间,嗯…在这方面在这种情况下,我将暂时说您需要调试到报表引擎库中,然后-正如我前面提到的,为项目获取源代码的新副本,在本地构建它,并引用它;它应该允许您跟踪问题实际发生的位置。在文件CodeReason.Reports.VS200\ReportPaginator.cs行472W中为我工作!谢谢
ContainerVisual smallerPage = new ContainerVisual( );
DrawingVisual pageVisual = page.Visual as DrawingVisual;
if ( pageVisual != null && pageVisual.Parent != null )
{
ContainerVisual parent = pageVisual.Parent as ContainerVisual;
parent.Children.Remove( pageVisual );
}
smallerPage.Children.Add( page.Visual );