在 Silverlight 4 中打印多个 UIElement
我有一个页面有两个需要打印的 UIElement,一个是 StackPanel,另一个是用于显示测试分数的自定义图形控件。根据要显示的测试数量,图形控件可以是任意长度,因此有时我可以将两者都放在一页上,而其他时候则需要单独的页面。
将它们打印在单独的页面上效果很好,因为我只是将 UIElement 设置为页面视觉效果,我遇到的问题是我无法弄清楚如何将它们组合起来在单个页面上打印。我尝试在代码隐藏中创建一个 StackPanel 并向其中添加元素,但由于一个元素只能有一个父元素,因此我必须创建临时对象来保存每个元素,同时从原始父元素中删除,然后将临时值传递给新的 StackPanel 。问题是,在我这样做之后,所有绑定的数据都会丢失
任何想法都会很棒!谢谢。
I have a page that has two UIElement
s that need to be printed, one is a StackPanel
and the other is a custom graph control for displaying test scores. The graph control could be any length based on the number of tests to display, so sometimes I will be able to fit both on one page and other times will need separate pages.
Printing them on separate pages works fine as I just set the UIElement to the pagevisual, the problem I am having is that I can't figure out how to combine them for printing on a single page. I tried creating a StackPanel in the codebehind and adding the elements to it, but since an element can only have one parent I have to create temporary objects to hold each one while I remove from the original parent and then give the temp to the new StackPanel. The problem is that after I do that all the bound data goes missing
Any ideas would be awesome! Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建这些元素的快照并仅将图像添加到
StackPanel
中,而不是将实际元素添加到StackPanel
中进行打印。您可以使用以下方法从UIElement
创建Image
:Instead of adding actual elements to the
StackPanel
for printing, you can create snapshots of those elements and add only images to theStackPanel
. You can use the following method to created anImage
from aUIElement
:或者将图像放入
Canvas
中,然后比较Canvas
的高度和图像高度来计算页数。Or just put the image in a
Canvas
and then compareCanvas
's height and image height to calculate number of pages.