AnimationElement GetAnimationElement(int listIndex) { AnimationElement element; if (!animationElements.TryGetValue(listIndex, out element)) { element = new AnimationElement(); animationElements[listIndex] = element; } return(element); }
void StartAnimation(Racer racer, Color color) { AnimationElement element = GetAnimationElement(racer); DoubleAnimation speedAnimation = new DoubleAnimation() { To = racer.Speed, AccelerationRatio = 0.5, DecelerationRatio = 0.5, Duration = new Duration(TimeSpan.FromSeconds(5)) }; ColorAnimation colorAnimation = new ColorAnimation() { From = color, To = Colors.Transparent, Duration = new Duration(TimeSpan.FromSeconds(5)) }; element.BeginAnimation(AnimationElement.CurrentSpeedProperty, speedAnimation); element.BeginAnimation(AnimationElement.SpeedColorProperty, colorAnimation); }