我想找到一种更简洁的方法来获取动画完成回调,以便在== from时触发。现在我通过向我的价值中添加一小部分来破解这个工作。还有更好的方法吗?
//todo is there a way to get animations to call their Complete() even when to == from?
if (to.Equals(from)) {
from += .01;
}
DoubleAnimation animation = new DoubleAnimation {
Name = axis == Axis.X ? TranslateTransform.XProperty.Name : TranslateTransform.YProperty.Name,
From = from,
To = to,
Duration = TimeSpan.FromSeconds(translate.Time),
FillBehavior = FillBehavior.Stop,
EasingFunction = translate.Curve.ToEase(),
IsAdditive = false,
};
AnimationClock = animation.CreateClock();
AnimationClock.Completed += (sender, args) => {
};
答案 0 :(得分:0)
您可以在创建动画之前检查值 如果持续时间很重要,您可以启动计时器并在计时器启动时启动。
这样的事情可以解决问题:
if (to.Equals(from)) {
if (_timer == null)
{
_timer = new Timer(x =>
{
//completeCode
}, null, translate.Time * 1000, Timeout.Infinite);
}
else
{
_timer.Change(translate.Time * 1000, Timeout.Infinite);
}
return;
}