如何克隆Silverlight视觉树结构 [英] How to clone Silverlight visual tree structure

查看:54
本文介绍了如何克隆Silverlight视觉树结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题与在Silverlight 4中打印中所述的问题相同。


为了解决这个问题,我尝试在打印前缩放视觉树的变换根。

I have the same problem as the question stated in "Printing in Silverlight 4".
To get around the problem, I have tried to scale transform root of my visual tree before printing.

    void document_PrintPage(object sender, PrintPageEventArgs e)
    {
        var renderScale = 1.0D;
        if (LayoutRoot.ActualWidth > e.PrintableArea.Width)
            renderScale = e.PrintableArea.Width/LayoutRoot.ActualWidth;

        var scaleTransform = new ScaleTransform();
        scaleTransform.ScaleX *= renderScale;
        scaleTransform.ScaleY *= renderScale;

        e.PageVisual = LayoutRoot;
        e.PageVisual.RenderTransform = scaleTransform;
    }

上面的代码现在可以在一张纸上正确显示Silverlight视觉效果。

Now above code correctly prints out with silverlight visuals fit on a piece of paper.

现在的问题是 LayoutRoot 本身现在在屏幕上缩小了。


问题是,在应用缩放变换之前,有没有办法让我创建 LayoutRoot 的副本?

The problem now is that LayoutRoot itself is now scaled down on the screen.
The question is, is there a way for me to create a clone of LayoutRoot before applying scale transform?

我的解决方法是在打印后再次应用比例转换,但我想知道是否有一种方法可以克隆视觉树

My walk-around is to applying the scale tranformation again after printing but I'd like to know if there is a way to clone visual tree

推荐答案

我的天哪,谢谢您的提问。我遇到了同样的问题,但试图将容器的尺寸(已经在可视化树中)设置为可打印区域,这对起作用,因为另一遍布局似乎是需要。 ScaleTransform 确实在这里可以正常工作。

My goodness, thanks for the question. I had the same problem but tried to fiddle about with setting the dimensions of a container (that is already in the visual tree) to the printable area, which does not work, as another layout pass seems to be required. ScaleTransform does work here however instantly.

只需在 EndPrint 事件中执行 myContainer.ClearValue(FrameworkElement.RenderTransformProperty)。尝试克隆可视化树会产生很多其他问题(我的加载内容有延迟等)。

I'm fine with the "work around" by just doing a myContainer.ClearValue(FrameworkElement.RenderTransformProperty) in the EndPrint event. Trying to clone the visual tree will yield a plethora of other issues (I have lazy loading content etc).

这篇关于如何克隆Silverlight视觉树结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆