我使用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();
然而,宽度和高度动画不起作用。有关如何解决它的任何指示?
答案 0 :(得分:1)
使用MSDN论坛中的相关帖子修正了此问题 - http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/e660077c-1a8f-463c-a118-ebb4de008176/
宽度和高度是相关动画,因此必须使用以下代码显式启用它:
widthAnimation.EnableDependentAnimation = true;
heightAnimation.EnableDependentAnimation = true;