private static void DisplayedValueChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { AnnularProgressBar t = (AnnularProgressBar)d; double value = (double)e.NewValue; UIElement[] layers; if (value < 0.25) { layers = new UIElement[] { t.HeadEllipse, t.PathL, t.PathR, t.TailEllipse }; } else if (value < 0.50) { layers = new UIElement[] { t.TailEllipse, t.HeadEllipse, t.PathL, t.PathR }; } else if (value < 0.75) { layers = new UIElement[] { t.TailEllipse, t.HeadEllipse, t.PathL, t.PathR }; } else { layers = new UIElement[] { t.PathR, t.TailEllipse, t.HeadEllipse, t.PathL }; } for (int i = 0; i < layers.Length; i++) { Panel.SetZIndex(layers[i], i); } }
private static void ValueChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { AnnularProgressBar t = (AnnularProgressBar)d; Storyboard valueStoryboard = new Storyboard(); if ((double)e.NewValue == -1) { DoubleAnimation valueAnimation = new DoubleAnimation(1, new Duration(TimeSpan.FromSeconds(0.5))) { EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; Storyboard.SetTarget(valueAnimation, d); Storyboard.SetTargetProperty(valueAnimation, new PropertyPath(DisplayedValueProperty)); valueStoryboard.Children.Add(valueAnimation); Storyboard opacityStoryboard = new Storyboard(); DoubleAnimation opacityAnimation = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(0.5))) { EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut }, }; Storyboard.SetTarget(opacityAnimation, t.ProgressGrid); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(OpacityProperty)); opacityStoryboard.Children.Add(opacityAnimation); valueStoryboard.Completed += (sender, e1) => { opacityStoryboard.Begin(); }; } else { DoubleAnimation valueAnimation = new DoubleAnimation((double)e.NewValue, new Duration(TimeSpan.FromSeconds(0.5))) { EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; Storyboard.SetTarget(valueAnimation, d); Storyboard.SetTargetProperty(valueAnimation, new PropertyPath(DisplayedValueProperty)); if ((double)e.OldValue == -1) { valueAnimation.From = 0; Storyboard opacityStoryboard = new Storyboard(); DoubleAnimation opacityAnimation = new DoubleAnimation(1, new Duration(TimeSpan.FromSeconds(0.5))) { EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut } }; Storyboard.SetTarget(opacityAnimation, t.ProgressGrid); Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath(OpacityProperty)); opacityStoryboard.Children.Add(opacityAnimation); opacityStoryboard.Begin(); } valueStoryboard.Children.Add(valueAnimation); } valueStoryboard.Begin(); }