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
I found this Silverlight reporting
and I resolved the issue…