[英]WP7 : Can't get Canvas.RenderTransform value
I have about 3-4 canvas controls and each contains about 750-1200 paths. 我有大约3-4个画布控件,每个控件包含大约750-1200个路径。 Users needs to make some transform to them and I use for that a global
用户需要对其进行一些转换,而我将其用于
Canvas SelectedCanvas;
Initially (in the constructor) SelectedCanvas takes the value of one my canvas controls. 最初(在构造函数中)SelectedCanvas接受我的画布控件之一的值。
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
}
}
I also tried this link and this link but I need also to get the value of RenderTransform
. 我也尝试了这个链接和这个链接,但是我还需要获取
RenderTransform
的值。 Am I doing something wrong? 难道我做错了什么? Thanks in advance!
提前致谢!
The default value of the RenderTransform property is Transform.Identity . RenderTransform属性的默认值为Transform.Identity 。 You have to apply a Transform, eg a RotateTransform, to your Canvas before you can manipulate it.
您必须先对Canvas应用一个Transform,例如RotateTransform,然后才能对其进行操作。
If you use a RotateTransform your code would have to look like this: 如果使用RotateTransform,则代码必须如下所示:
RotateTransform t = bd1.RenderTransform as RotateTransform;
if (t.Angle >= 360)
t.Angle = 0;
t.Angle += 30;
or: 要么:
RotateTransform t = bd1.RenderTransform as RotateTransform;
t.Angle = (t.Angle + 30) % 360;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.