【发布时间】:2010-08-22 03:32:17
【问题描述】:
我正在用 Silverlight 制作时钟。我正在尝试以编程方式设置动画代码,因为我想为 3 个时钟指针中的每一个重复使用相同的代码(而且我认为我不能使用 xaml 中的单个故事板来做到这一点)。
public void Rotate(double toAngle, RotateTransform rotate)
{
Storyboard sb = new Storyboard();
DoubleAnimationUsingKeyFrames keyframes = new DoubleAnimationUsingKeyFrames();
EasingDoubleKeyFrame easingStart = new EasingDoubleKeyFrame();
easingStart.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
easingStart.Value = rotate.Angle;
EasingDoubleKeyFrame easingEnd = new EasingDoubleKeyFrame();
easingEnd.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5));
easingEnd.Value = toAngle;
var ease = new ElasticEase();
ease.EasingMode = EasingMode.EaseIn;
easingEnd.EasingFunction = ease;
keyframes.KeyFrames.Add(easingStart);
keyframes.KeyFrames.Add(easingEnd);
Storyboard.SetTarget(keyframes, rotate);
Storyboard.SetTargetProperty(keyframes, new PropertyPath("(RotateTransform.Angle)"));
sb.Children.Add(keyframes);
sb.Begin();
}
我传入了我希望当前手旋转到的角度和该手的旋转变换。从这个旋转变换中,我得到了起始角度。
当我运行时钟时,时钟指针会移动(秒针每秒移动到正确的位置等),但动画似乎并没有实际动画。他们只是从头到尾立即结束。
为什么动画不能正常发生?
【问题讨论】:
标签: c# silverlight-4.0