打印运行时用户控件 silverlight 4

发布于 2024-12-17 18:37:17 字数 1528 浏览 0 评论 0原文

我的 silverlight 应用程序有一个用户控件(称为 CertificatePrintControl),用于显示和打印一些信息。 我想在另一个控件内实例化 printCtl 并在运行时打印内容。 例子是:

foreach (var certId in CertToPrint)
    {
        var certPrintController = new CertificatePrintControl() { PrintDocument = pd, CertGuid = certId };
        certPrintController.Print();
        certPrintController = null;
    }

问题是在CertificatePrintControl内部有这段代码,

    void pd_PrintPage(object sender, PrintPageEventArgs e)
    {
        try
        {
            var oldW = lstMainPrintCertificate.Width;
            var oldH = lstMainPrintCertificate.Height;
            lstMainPrintCertificate.Width = e.PrintableArea.Width;
            lstMainPrintCertificate.Height = e.PrintableArea.Height;
            e.PageVisual = lstMainPrintCertificate;
            lstMainPrintCertificate.Width = oldW;
            lstMainPrintCertificate.Height = oldH;
        }
        catch (Exception ex)
        { 
            //
        }
    }

 {System.InvalidOperationException: Element is already the child of another element.
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
   at System.Windows.Printing.PrintPageEventArgs.set_PageVisual(UIElement value)
   at com.breathesaftey.Control.CertificatePrintControl.pd_PrintPage(Object sender, PrintPageEventArgs e)}

可能已经理解了原因,但我找不到解决方法。

谢谢

My silverlight application has a usercontrol (called CertificatePrintControl) that is used to display and print some information.
I would like, inside another control, to istantiate the printCtl and print the content at runtime.
The example is:

foreach (var certId in CertToPrint)
    {
        var certPrintController = new CertificatePrintControl() { PrintDocument = pd, CertGuid = certId };
        certPrintController.Print();
        certPrintController = null;
    }

The problem is that inside the CertificatePrintControl there's this code

    void pd_PrintPage(object sender, PrintPageEventArgs e)
    {
        try
        {
            var oldW = lstMainPrintCertificate.Width;
            var oldH = lstMainPrintCertificate.Height;
            lstMainPrintCertificate.Width = e.PrintableArea.Width;
            lstMainPrintCertificate.Height = e.PrintableArea.Height;
            e.PageVisual = lstMainPrintCertificate;
            lstMainPrintCertificate.Width = oldW;
            lstMainPrintCertificate.Height = oldH;
        }
        catch (Exception ex)
        { 
            //
        }
    }

that gives

 {System.InvalidOperationException: Element is already the child of another element.
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
   at System.Windows.Printing.PrintPageEventArgs.set_PageVisual(UIElement value)
   at com.breathesaftey.Control.CertificatePrintControl.pd_PrintPage(Object sender, PrintPageEventArgs e)}

I may have understood why but I can't find a workaround.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2024-12-24 18:37:17

我发现了这个 Silverlight reporting

并且解决了这个问题...

I found this Silverlight reporting

and I resolved the issue...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文