以下代码在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");
但是当你运行它时,什么也不会发生。
如果将属性从“Width”更改为“Opacity”(还要更改From = 0和To = 1),那么可以正常工作。
“Width”的问题是什么?
EventTrigger
(http://msdn.microsoft.com/en-us/library/system.windows.eventtrigger.aspx)将所有代码移动到xaml中呢? - RredCat