// ReSharper disable VirtualMemberNeverOverriden.Global protected virtual void OnStateChanged(ProgressState oldState, ProgressState newState) // ReSharper restore VirtualMemberNeverOverriden.Global { var peer = UIElementAutomationPeer.FromElement(this) as ProgressAutomationPeer; if (peer != null) { peer.InvalidatePeer(); } if (IsEnabled) { switch (newState) { case ProgressState.Busy: VisualStateManager.GoToState(this, "Busy", true); if (IndeterminateAnimation != null && IsIndeterminateAnimationRunning) { IsIndeterminateAnimationRunning = false; IndeterminateAnimation.Stop(this); } if (BusyAnimation != null) { BusyAnimation.Begin(this, Template, true); IsBusyAnimationRunning = true; } break; case ProgressState.Indeterminate: VisualStateManager.GoToState(this, "Indeterminate", true); if (BusyAnimation != null && IsBusyAnimationRunning) { IsBusyAnimationRunning = false; BusyAnimation.Stop(this); } if (IndeterminateAnimation != null) { IndeterminateAnimation.Begin(this, Template, true); IsIndeterminateAnimationRunning = true; } break; case ProgressState.Normal: VisualStateManager.GoToState(this, "Normal", true); if (IndeterminateAnimation != null && IsIndeterminateAnimationRunning) { IsIndeterminateAnimationRunning = false; IndeterminateAnimation.Stop(this); } if (BusyAnimation != null && IsBusyAnimationRunning) { IsBusyAnimationRunning = false; BusyAnimation.Stop(this); } break; } } }
private void UpdateIndeterminateAnimation() { if ((IndeterminateAnimation == null || (IndeterminateAnimation != null && IndeterminateAnimation.Name == DefaultIndeterminateAnimationName)) && Track != null && _indicator != null) { if (IndeterminateAnimation != null && IsIndeterminateAnimationRunning) { IsIndeterminateAnimationRunning = false; IndeterminateAnimation.Stop(this); IndeterminateAnimation.Remove(this); } IndeterminateAnimation = new Storyboard { Name = DefaultIndeterminateAnimationName, RepeatBehavior = RepeatBehavior.Forever }; var indicatorSize = Orientation == Orientation.Horizontal ? _indicator.Width : _indicator.Height; var trackSize = Orientation == Orientation.Horizontal ? Track.ActualWidth : Track.ActualHeight; var time = trackSize / 100; var animation = new DoubleAnimationUsingKeyFrames { Duration = new Duration(TimeSpan.FromSeconds(time + 0.5)) }; // NOTE: Lack of contracts: DoubleAnimationUsingKeyFrames.KeyFrames is always have collection instance Contract.Assume(animation.KeyFrames != null); animation.KeyFrames.Add(new DiscreteDoubleKeyFrame(-indicatorSize - 1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)))); animation.KeyFrames.Add(new LinearDoubleKeyFrame(trackSize + 1, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(time)))); Storyboard.SetTarget(animation, _indicator); Storyboard.SetTargetProperty(animation, new PropertyPath(Orientation == Orientation.Horizontal ? Canvas.LeftProperty : Canvas.TopProperty)); // NOTE: Lack of contracts Contract.Assume(IndeterminateAnimation != null); Contract.Assume(IndeterminateAnimation.Children != null); IndeterminateAnimation.Children.Add(animation); if (IndeterminateAnimation.CanFreeze) { IndeterminateAnimation.Freeze(); } if (State == ProgressState.Indeterminate && IsEnabled) { IndeterminateAnimation.Begin(this, Template, true); IsIndeterminateAnimationRunning = true; } } }
private void UpdateIndeterminateAnimation() { if ((IndeterminateAnimation == null || (IndeterminateAnimation != null && IndeterminateAnimation.Name == DefaultIndeterminateAnimationName)) && Track != null && _arc != null) { if (IndeterminateAnimation != null && IsIndeterminateAnimationRunning) { IsIndeterminateAnimationRunning = false; IndeterminateAnimation.Stop(this); IndeterminateAnimation.Remove(this); } IndeterminateAnimation = new Storyboard { Name = DefaultIndeterminateAnimationName, RepeatBehavior = RepeatBehavior.Forever }; var trackSize = Math.Min(Track.ActualWidth, Track.ActualHeight); var time = (trackSize * Math.PI) / 100; var startAngleSetValueAnimation = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(0d))); Storyboard.SetTarget(startAngleSetValueAnimation, _arc); Storyboard.SetTargetProperty(startAngleSetValueAnimation, new PropertyPath(Arc.StartAngleProperty)); var endAngleSetValueAnimation = new DoubleAnimation(-270, new Duration(TimeSpan.FromSeconds(0d))); Storyboard.SetTarget(endAngleSetValueAnimation, _arc); Storyboard.SetTargetProperty(endAngleSetValueAnimation, new PropertyPath(Arc.EndAngleProperty)); var startAngleAnimation = new DoubleAnimationUsingKeyFrames(); // NOTE: Lack of contracts: DoubleAnimationUsingKeyFrames.KeyFrames is always have collection instance Contract.Assume(startAngleAnimation.KeyFrames != null); startAngleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(360, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(time)))); Storyboard.SetTarget(startAngleAnimation, _arc); Storyboard.SetTargetProperty(startAngleAnimation, new PropertyPath(Arc.StartAngleProperty)); var endAngleAnimation = new DoubleAnimationUsingKeyFrames(); // NOTE: Lack of contracts: DoubleAnimationUsingKeyFrames.KeyFrames is always have collection instance Contract.Assume(endAngleAnimation.KeyFrames != null); endAngleAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(90, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(time)))); Storyboard.SetTarget(endAngleAnimation, _arc); Storyboard.SetTargetProperty(endAngleAnimation, new PropertyPath(Arc.EndAngleProperty)); // NOTE: Lack of contracts Contract.Assume(IndeterminateAnimation != null); Contract.Assume(IndeterminateAnimation.Children != null); IndeterminateAnimation.Children.Add(startAngleSetValueAnimation); IndeterminateAnimation.Children.Add(endAngleSetValueAnimation); IndeterminateAnimation.Children.Add(startAngleAnimation); IndeterminateAnimation.Children.Add(endAngleAnimation); if (IndeterminateAnimation.CanFreeze) { IndeterminateAnimation.Freeze(); } if (State == ProgressState.Indeterminate && IsEnabled) { IndeterminateAnimation.Begin(this, Template, true); IsIndeterminateAnimationRunning = true; } } }