【问题标题】:Animate a canvas programatically using StoryBoard API in Windows Store App使用 Windows Store App 中的 StoryBoard API 以编程方式为画布设置动画
【发布时间】:2013-05-02 22:44:33
【问题描述】:

我正在使用 StoryBoard API 在 Windows 应用商店应用中为画布制作动画:

        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();

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

【问题讨论】:

    标签: xaml storyboard windows-store-apps


    【解决方案1】:

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

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

        widthAnimation.EnableDependentAnimation = true;
        heightAnimation.EnableDependentAnimation = true;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-17
      • 2017-03-31
      • 2012-01-24
      相关资源
      最近更新 更多