打印运行时usercontrol silverlight 4

时间:2011-11-23 14:06:57

标签: silverlight exception printing runtime

我的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)}

我可能已经理解了为什么,但我找不到解决方法。

由于

1 个答案:

答案 0 :(得分:0)

我发现了Silverlight reporting

我解决了这个问题...