在WPF中翻译变换和旋转

时间:2014-04-29 07:54:18

标签: c# wpf

翻译工作正常,但没有轮换,你能帮帮我吗?

TranslateTransform trans = new TranslateTransform();

Pointer.RenderTransform = trans;

DoubleAnimation animX = new DoubleAnimation(fromX, toX, TimeSpan.FromMilliseconds(325));
DoubleAnimation animY = new DoubleAnimation(fromY, toY, TimeSpan.FromMilliseconds(325));

DoubleAnimation rotateBy = new DoubleAnimation(0, 90, TimeSpan.FromMilliseconds(325));

animX.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
animY.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };

animX.Completed += new EventHandler(myanim_Completed);
trans.BeginAnimation(TranslateTransform.XProperty, animX);
trans.BeginAnimation(TranslateTransform.YProperty, animY);

trans.BeginAnimation(RotateTransform.AngleProperty, rotateBy);

1 个答案:

答案 0 :(得分:3)

TranslateTransform没有Angle属性。您应该使用TransformGroup

var group = new TransformGroup();
var trans = new TranslateTransform();
group.Children.Add(trans);
var rotate = new RotateTransform();
group.Children.Add(rotate);

Pointer.RenderTransform = group;

// the rest of the code is fine; only the last line needs fixing:

rotate.BeginAnimation(RotateTransform.AngleProperty, rotateBy);

您还应该考虑使用Storyboard对动画进行分组。