代码隐藏中的 WinRT/Metro 动画 [英] WinRT/Metro Animation in code-behind
本文介绍了代码隐藏中的 WinRT/Metro 动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码在 Silverlight 中运行良好:
The following code works fine in Silverlight:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Storyboard storyboard = new Storyboard();
DoubleAnimation doubleAnimation = new DoubleAnimation();
doubleAnimation.From = 50;
doubleAnimation.To = 100;
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
doubleAnimation.AutoReverse = true;
doubleAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(200));
storyboard.Children.Add(doubleAnimation);
Storyboard.SetTarget(doubleAnimation, button1);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));
storyboard.Begin();
}
在 WinRT/Metro 中,它需要一个小改动才能编译:
In WinRT/Metro it needs one minor change to make it compile:
Storyboard.SetTargetProperty(doubleAnimation, "Width");
但是当你运行它时,什么也没有发生.
but when you run it, nothing happens.
如果您将属性从宽度"更改为不透明度"(同时更改 From=0 和 To=1),则有效.
If you change the property from "Width" to "Opacity" (also change From=0 and To=1) that works.
宽度"有什么问题?
推荐答案
需要添加以下内容:
doubleAnimation.EnableDependentAnimation = true;
这似乎解决了问题.
这篇关于代码隐藏中的 WinRT/Metro 动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文