我想将矩形的背景颜色更改为绿色 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));