【发布时间】:2010-11-20 16:49:54
【问题描述】:
我在 Silverlight 3 中遇到了一个非常奇怪的问题。我定义了一个扩展方法来围绕给定的 DoubleAnimation 创建故事板并播放该动画。我知道 Silverlight 中故事板的默认持续时间是 1 秒,但我想为我的动画更改它。但是,当我设置不同的持续时间时,不是将动画更改为在分配的时间内从开始移动到结束,动画只会播放我指定的持续时间然后停止。例如,如果我将某物从 0,0 移动到 0,10 并将持续时间设置为 0.3 秒,则该项目只会移动到 0.3。我无法想象这是设计使然。有什么想法吗?
这是我正在使用的代码。 ConfigureStoryboard 是围绕动画创建情节提要的地方。我删除了一些关于缓动函数的代码,使其更具可读性。
public static void BeginAnimation(
this Transform transform,
DependencyProperty property,
DoubleAnimation animation,
EasingFunction function
)
{
var storyboard = new Storyboard();
ConfigureStoryboard(animation, storyboard, function);
Storyboard.SetTarget(storyboard, transform);
Storyboard.SetTargetProperty(
storyboard,
new PropertyPath(property));
storyboard.Begin();
}
private static void ConfigureStoryboard(DoubleAnimation animation, Storyboard storyboard, EasingFunction function)
{
DoubleAnimation myAnimation = new DoubleAnimation();
storyboard.Duration = animation.Duration;
myAnimation.From = animation.From;
myAnimation.To = animation.To;
storyboard.Children.Add(myAnimation);
}
【问题讨论】:
标签: c# .net silverlight