public static void PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TextBlock element = (TextBlock)d; PlaylistItem curr = (PlaylistItem)element.GetValue(AnimatedCurrentItemProperty); PlaylistItem item = element.DataContext as PlaylistItem; if (curr != null && item != null && curr.UID == item.UID) { GradientStop stop1 = new GradientStop(Color1, -2d); GradientStop stop2 = new GradientStop(Color2, -1d); GradientStop stop3 = new GradientStop(Color1, 0d); GradientStop stop4 = new GradientStop(Color2, 1d); element.Background = new LinearGradientBrush(new GradientStopCollection(new List<GradientStop> { stop1, stop2, stop3, stop4 })); stop1.BeginAnimation(GradientStop.OffsetProperty, new DoubleAnimation(-2, 0, duration) { RepeatBehavior = RepeatBehavior.Forever }); stop2.BeginAnimation(GradientStop.OffsetProperty, new DoubleAnimation(-1, 1, duration) { RepeatBehavior = RepeatBehavior.Forever }); stop3.BeginAnimation(GradientStop.OffsetProperty, new DoubleAnimation(0, 2, duration) { RepeatBehavior = RepeatBehavior.Forever }); stop4.BeginAnimation(GradientStop.OffsetProperty, new DoubleAnimation(1, 3, duration) { RepeatBehavior = RepeatBehavior.Forever }); } else { element.Background = Brushes.Transparent; } }
private void startProgress(object sender, RoutedEventArgs e) { progressBar1.Width = this.width; progressBar1.Height = this.height; progressBar1.Margin = new Thickness(3, 3, 0, 0); border1.Margin = new Thickness(0); border1.Width = this.width + 6; border1.Height = this.height + 6; SolidColorBrush scb = new SolidColorBrush(Colors.PaleGreen); LinearGradientBrush lgb = new LinearGradientBrush(); GradientStop stop1 = new GradientStop(Colors.GreenYellow, 0.0); GradientStop stop2 = new GradientStop(Colors.LightBlue, 0.5); GradientStop stop3 = new GradientStop(Colors.Violet, 1.0); lgb.GradientStops.Add(stop1); lgb.GradientStops.Add(stop2); lgb.GradientStops.Add(stop3); Rectangle r = (Rectangle)progressBar1.Template.FindName("bar", progressBar1); r.Fill = lgb; progressBar1.ValueChanged += new RoutedPropertyChangedEventHandler<double>(progressBar1_ValueChanged); DoubleAnimation da = new DoubleAnimation(); da.From = 0; da.To = 100; da.Duration = new Duration(TimeSpan.FromSeconds(totalTime)); progressBar1.BeginAnimation(ProgressBar.ValueProperty, da); ColorAnimation ca1 = new ColorAnimation(); ca1.To = Colors.Yellow; ca1.Duration = new Duration(TimeSpan.FromSeconds(totalTime)); stop1.BeginAnimation(GradientStop.ColorProperty, ca1); ColorAnimation ca2 = new ColorAnimation(); ca2.To = Colors.Orange; ca2.Duration = new Duration(TimeSpan.FromSeconds(totalTime)); stop2.BeginAnimation(GradientStop.ColorProperty, ca2); ColorAnimation ca3 = new ColorAnimation(); ca3.To = Colors.Tomato; ca3.Duration = new Duration(TimeSpan.FromSeconds(totalTime)); stop3.BeginAnimation(GradientStop.ColorProperty, ca3); }