以下代码在 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),则可以。
“宽度”有什么问题?