長方形の背景色を黒に戻すよりも1秒間緑に変えたい。ライトがオンまたはオフになっていることをシミュレートしたい-色をフェードインしたくない。以下のコードは、黒から緑に、またはその逆にフェードすることを除いて、私が望むことを実行します。私は間違いなくUIスレッドでスリープしたくない.........。
ColorAnimation animation = new ColorAnimation { From = Colors.Black, To = Colors.LightGreen, Duration = new Duration(TimeSpan.FromSeconds(1)), RepeatBehavior= new RepeatBehavior(1), AutoReverse=true };
SolidColorBrush activityLight = new System.Windows.Media.SolidColorBrush(Colors.Black);
ActivityIndicator.Fill = activityLight;
this.RegisterName("activityLight", activityLight);
ActivityStoryboard = new Storyboard();
ActivityStoryboard.Children.Add(animation);
Storyboard.SetTargetName(animation, "activityLight");
Storyboard.SetTargetProperty(animation, new PropertyPath(SolidColorBrush.ColorProperty));