0

我正在使用 StoryBoard API 在 Windows Store 应用程序中为画布制作动画:

        DoubleAnimation widthAnimation = new DoubleAnimation();
        DoubleAnimation heightAnimation = new DoubleAnimation();

        widthAnimation.BeginTime = new TimeSpan(0, 0, 0, 0, outDuration + inDuration);
        heightAnimation.BeginTime = new TimeSpan(0, 0, 0, 0, outDuration + inDuration);
        widthAnimation.Duration = new TimeSpan(0, 0, 0, 0, collapseDuration);
        heightAnimation.Duration = new TimeSpan(0, 0, 0, 0, collapseDuration);

        Storyboard.SetTarget(widthAnimation, target);
        Storyboard.SetTargetProperty(widthAnimation, "Width");
        Storyboard.SetTarget(heightAnimation, target);
        Storyboard.SetTargetProperty(heightAnimation, "Height");

        widthAnimation.From = beginSize.Width;
        widthAnimation.To = endSize.Width;
        heightAnimation.From = beginSize.Height;
        heightAnimation.To = endSize.Height;

        Storyboard stb = new Storyboard();
        stb.Children.Add(widthAnimation);
        stb.Children.Add(heightAnimation);

        stb.Begin();

但是宽度和高度动画不起作用。有关如何解决它的任何指示?

4

1 回答 1

1

使用 MSDN 论坛中的相关帖子修复了此问题 - http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/e660077c-1a8f-463c-a118-ebb4de008176/

宽度和高度是依赖动画,因此必须使用以下代码显式启用:

    widthAnimation.EnableDependentAnimation = true;
    heightAnimation.EnableDependentAnimation = true;
于 2013-05-08T16:46:05.560 回答