WPF中的平移变换和旋转

本文关键字:旋转 平移变换 WPF | 更新日期: 2023-09-27 18:00:35

翻译很好,但没有旋转,你能帮我吗?

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);

WPF中的平移变换和旋转

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对动画进行分组。