rotating
button
click
180 degree
位于AnimationServices.RotationAnimation((FrameworkElement)sender, 180, 1, "Y"); // working
,工作正常
rotating
但是当我按AnimationServices.RotationAnimation((FrameworkElement)sender, 90, 1, "Y");
AnimationServices.RotationAnimation((FrameworkElement)sender, 90, 1, "Y"); // not working
做同样的事情时,两次90度角比不工作
rotating
仅90 degree
一个internal static void RotationAnimation(FrameworkElement sender, int Angle, int DurationInMSec, String Axis)
{
var storyboard = new Storyboard();
var easingDoubleKeyFrame1 = new EasingDoubleKeyFrame
{
KeyTime = TimeSpan.FromMilliseconds(0),
Value = 0
};
var easingDoubleKeyFrame2 = new EasingDoubleKeyFrame
{
KeyTime = TimeSpan.FromMilliseconds(DurationInMSec),
Value = Angle
};
var doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
doubleAnimationUsingKeyFrames.KeyFrames.Add(easingDoubleKeyFrame1);
doubleAnimationUsingKeyFrames.KeyFrames.Add(easingDoubleKeyFrame2);
var rotateTransform = new PlaneProjection();
var button = (FrameworkElement)sender;
button.Projection = rotateTransform;
Storyboard.SetTarget(doubleAnimationUsingKeyFrames, rotateTransform);
Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, new PropertyPath("Rotation" + Axis));
storyboard.Children.Add(doubleAnimationUsingKeyFrames);
storyboard.Begin();
}
角度
有没有人对这个奇怪的问题有任何想法?
更新
{{1}}
答案 0 :(得分:1)
如果您不提供RotationAnimation
方法的代码,很难说出发生了什么。尽管如此,这种方法很可能同时尝试两次执行相同的动画。所以你有两个动画试图将相同的元素从0度旋转到90度。这使得... 90度。更改当前正在执行的动画的旋转角度,或者在启动新动画之前等待当前动画完成执行。要求两个不同的动画同时动画相同的属性不可能提供一致的结果。
编辑:看到你的代码后,确实是问题所在。你正在创建两个动画,它们都会从0度旋转到90度。您需要链接两个动画,并在方法中添加“origin”参数,以便第二个动画将从90°开始旋转(而不是从0开始)。要链接动画,您可以修改方法以返回创建的动画,然后订阅Completed
事件。
类似的东西:
internal static Storyboard RotationAnimation(FrameworkElement sender, int origin, int Angle, int DurationInMSec, String Axis)
{
var storyboard = new Storyboard();
var easingDoubleKeyFrame1 = new EasingDoubleKeyFrame
{
KeyTime = TimeSpan.FromMilliseconds(0),
Value = origin
};
var easingDoubleKeyFrame2 = new EasingDoubleKeyFrame
{
KeyTime = TimeSpan.FromMilliseconds(DurationInMSec),
Value = Angle + origin
};
var doubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();
doubleAnimationUsingKeyFrames.KeyFrames.Add(easingDoubleKeyFrame1);
doubleAnimationUsingKeyFrames.KeyFrames.Add(easingDoubleKeyFrame2);
var rotateTransform = new PlaneProjection();
var button = (FrameworkElement)sender;
button.Projection = rotateTransform;
Storyboard.SetTarget(doubleAnimationUsingKeyFrames, rotateTransform);
Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrames, new PropertyPath("Rotation" + Axis));
storyboard.Children.Add(doubleAnimationUsingKeyFrames);
storyboard.Begin();
return storyboard;
}
然后你可以这样称呼它:
var storyboard = RotateAnimation((FrameworkElement)sender, 0, 90, 1, "Y");
storyboard.Completed += (s, e) => RotateAnimation((FrameworkElement)sender, 90, 90, 1, "Y");