BaconographyWP8.Common.ReorderListBox.AnimateRearrange C# (CSharp) Method

AnimateRearrange() public method

Animates movements, insertions, or deletions in the list.
The animations are as follows: - Inserted items fade in while later items slide down to make space. - Removed items fade out while later items slide up to close the gap. - Moved items slide from their previous location to their new location. - Moved items which move out of or in to the visible area also fade out / fade in while sliding.

The rearrange action callback is called in the middle of the rearrange process. That callback may make any number of changes to the list source, in any order. After the rearrange action callback returns, the net result of all changes will be detected and included in a dynamically generated rearrange animation.

Multiple calls to this method in quick succession will be automatically queued up and executed in turn to avoid any possibility of conflicts. (If simultaneous rearrange animations are desired, use a single call to AnimateRearrange with a rearrange action callback that does both operations.)

public AnimateRearrange ( Duration animationDuration, System.Action rearrangeAction ) : void
animationDuration Duration Duration of the animation.
rearrangeAction System.Action Performs the actual rearrange on the list source.
return void
        public void AnimateRearrange(Duration animationDuration, Action rearrangeAction)
        {
            if (rearrangeAction == null)
            {
                throw new ArgumentNullException("rearrangeAction");
            }

            if (this.rearrangeCanvas == null)
            {
                throw new InvalidOperationException("ReorderListBox control template is missing " +
                    "a part required for rearrange: " + ReorderListBox.RearrangeCanvasPart);
            }

            if (this.rearrangeQueue == null)
            {
                this.rearrangeQueue = new Queue<KeyValuePair<Action, Duration>>();
                this.scrollViewer.ScrollToVerticalOffset(this.scrollViewer.VerticalOffset); // Stop scrolling.
                this.Dispatcher.BeginInvoke(() =>
                    this.AnimateRearrangeInternal(rearrangeAction, animationDuration));
            }
            else
            {
                this.rearrangeQueue.Enqueue(new KeyValuePair<Action, Duration>(rearrangeAction, animationDuration));
            }
        }