我有工具栏(由边框包装),在需要时在运行时创建。我已经添加了一个动画方法来分别在创建或隐藏时增大或缩小工具栏高度。
问题在于,即使增长动画工作正常,当我反转值并导致缩小动画时,动画开始前总会有明显的延迟。
谁能告诉我可能导致这种情况的原因以及如何解决这个问题?
以下是我的动画功能的代码:
public static void AnimateBorder(Border border, int startHeight, int endHeight, int time)
{
DoubleAnimation stretch = new DoubleAnimation()
{
From = startHeight,
To = endHeight,
Duration = new TimeSpan(0, 0, time),
};
Storyboard.SetTarget(stretch, border);
Storyboard.SetTargetProperty(stretch, new PropertyPath(Border.MaxHeightProperty));
var sb = new Storyboard();
// Add event handler to remove shrunk border.
if (startHeight > endHeight)
{
sb.Completed += (sender, e) => Border_Collapsed(sender, e, border);
}
// Start animation.
sb.Children.Add(stretch);
sb.Begin();
}