C# WPF动画:如果to==from,则不调用完整回调
我想找到一种更简洁的方法,让动画在to==from时完全回调到fire。现在我通过在我的from值中添加一小部分来解决这个问题。有更好的办法吗C# WPF动画:如果to==from,则不调用完整回调,c#,wpf,animation,C#,Wpf,Animation,我想找到一种更简洁的方法,让动画在to==from时完全回调到fire。现在我通过在我的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 =
//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) => {
};
可以在创建动画之前检查值。 如果持续时间很重要,您可以启动计时器,并在它滴答作响时启动代码 像这样的事情应该可以做到:
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;
}
每次创建计时器并将其存储在类变量中时,都需要耗费大量资源。