Xaml 在Windows应用商店应用程序中使用情节提要API以编程方式设置画布动画

Xaml 在Windows应用商店应用程序中使用情节提要API以编程方式设置画布动画,xaml,storyboard,windows-store-apps,Xaml,Storyboard,Windows Store Apps,我正在使用情节提要API在Windows应用商店应用程序中设置画布动画: DoubleAnimation widthAnimation = new DoubleAnimation(); DoubleAnimation heightAnimation = new DoubleAnimation(); widthAnimation.BeginTime = new TimeSpan(0, 0, 0, 0, outDuration + inDuratio

我正在使用情节提要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();

但是,“宽度”和“高度”动画不起作用。关于如何解决此问题的任何建议?

使用MSDN论坛中的相关帖子修复了此问题-

宽度和高度取决于动画,因此必须使用以下代码显式启用:

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