WP7:无法获得 Canvas.RenderTransform 值 [英] WP7 : Can't get Canvas.RenderTransform value

查看:26
本文介绍了WP7:无法获得 Canvas.RenderTransform 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约 3-4 个画布控件,每个包含大约 750-1200 个路径.用户需要对他们进行一些转换,我为此使用了全局

I have about 3-4 canvas controls and each contains about 750-1200 paths. Users needs to make some transform to them and I use for that a global

    Canvas SelectedCanvas;

最初(在构造函数中)SelectedCanvas 获取我的画布控件之一的值.

Initially (in the constructor) SelectedCanvas takes the value of one my canvas controls.

    SelectedCanvas = canvas1;

对于旋转画布的按钮,我使用下一个函数:

For the button wich rotates the canvas I use the next function:

    private void RotateRightLayerButton_Click(object sender, RoutedEventArgs e)
    {
        if (SelectedCanvas.RenderTransform != null)
        {
            //method 1
            CompositeTransform ct = canvas1.RenderTransform as CompositeTransform;
            if (ct.Rotation == 360)//ct will return NullException
                ct.Rotation = 0;
            ct.Rotation += 30;

            // method 2
            TransformGroup tg = canvas1.RenderTransform as TransformGroup;                
            (tg.Children[0] as RotateTransform).Angle += 30;
            //tg will return NullException                               
        }
    }

我也试过 这个链接此链接但我还需要获取 RenderTransform 的值.难道我做错了什么?提前致谢!

I also tried this link and this link but I need also to get the value of RenderTransform. Am I doing something wrong? Thanks in advance!

推荐答案

RenderTransform 属性是 Transform.Identity.您必须应用转换,例如一个 RotateTransform,在你可以操作它之前到你的 Canvas.

The default value of the RenderTransform property is Transform.Identity. You have to apply a Transform, e.g. a RotateTransform, to your Canvas before you can manipulate it.

如果您使用 RotateTransform,您的代码必须如下所示:

If you use a RotateTransform your code would have to look like this:

RotateTransform t = bd1.RenderTransform as RotateTransform; 
if (t.Angle >= 360) 
    t.Angle = 0; 
t.Angle += 30; 

或:

RotateTransform t = bd1.RenderTransform as RotateTransform; 
t.Angle = (t.Angle + 30) % 360; 

这篇关于WP7:无法获得 Canvas.RenderTransform 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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