次のコードは、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 では、コンパイルするために 1 つの小さな変更が必要です。
Storyboard.SetTargetProperty(doubleAnimation, "Width");
しかし、実行しても何も起こりません。
プロパティを「Width」から「Opacity」に変更すると (From=0 と To=1 も変更)、機能します。
「幅」の問題は何ですか?