/// <summary> /// Performs an animated iteration through the wrapped collection's /// elements. /// </summary> /// /// <param name="action"> /// the action to perform for every iteration through the collection. /// </param> /// <param name="duration"> /// the number of milliseconds that the animation should last. /// </param> /// <param name="interpolator"> /// the interpolation function that should be used for the animation. /// </param> public void ForEach(IterationAction action, long duration, Interpolator interpolator) { // Perform an animation that will animate through // all of the indices in the collection. var lastIndex = this.Collection.Count() - 1; var indexAnimation = new ValueAnimation(0, lastIndex, duration, interpolator); // Every time the index animation is iterated, iterate the // "loop" and perform the action for every item up to the // current index. int i = 0; indexAnimation.AnimationIncremented += (_, __) => { while (i <= indexAnimation.CurrentValue) { var element = this.Collection.ElementAt(i); action(element, i); i++; } }; // Add the index animation to the list of animations being // performed. this.AddAnimation(indexAnimation); // Start the animation. indexAnimation.Start(); }
/// <summary> /// Performs an animated iteration through the wrapped collection's /// elements. /// </summary> /// /// <param name="action"> /// the action to perform for every iteration through the collection. /// </param> /// <param name="interpolator"> /// the interpolation function that should be used for the animation. /// </param> public void ForEach(IterationAction action, Interpolator interpolator) { this.ForEach(action, this.DefaultDuration, interpolator); }
/// <summary> /// Performs an animated iteration through the wrapped collection's /// elements. /// </summary> /// /// <param name="action"> /// the action to perform for every iteration through the collection. /// </param> /// <param name="duration"> /// the number of milliseconds that the animation should last. /// </param> public void ForEach(IterationAction action, long duration) { this.ForEach(action, duration, this.DefaultInterpolator); }