打印运行时用户控件 silverlight 4
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了这个 Silverlight reporting
并且解决了这个问题...
I found this Silverlight reporting
and I resolved the issue...