Csharp/C#教程:代码隐藏中的WinRT / Metro动画分享


代码隐藏中的WinRT / Metro动画

以下代码在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中,它需要一个小的改动才能编译:

 Storyboard.SetTargetProperty(doubleAnimation, "Width"); 

但是当你运行它时,没有任何反应。

如果您将属性从“宽度”更改为“不透明度”(也可以更改从= 0和To = 1)。

“宽度”有什么问题?

您需要添加以下内容:

 doubleAnimation.EnableDependentAnimation = true; 

这似乎解决了这个问题。

我不确定但尝试使用:

 Storyboard.SetTargetProperty(doubleAnimation, Button.WidthProperty); 

代替

上述就是C#学习教程:代码隐藏中的WinRT / Metro动画分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 Storyboard.SetTargetProperty(doubleAnimation, "Width"); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/984685.html

(0)
上一篇 2021年12月20日
下一篇 2021年12月20日

精彩推荐