/// <summary>
        /// Clears the animation list.
        /// </summary>
        private void ClearButton_Click(object sender, RoutedEventArgs e)
        {
            Debug.Assert(IsRemoveEnabled);

            VisAnimItems.Clear();

            RefreshAnim();
        }
        /// <summary>
        /// Repositions an item in the animation list, moving it down one slot.
        /// </summary>
        private void DownButton_Click(object sender, RoutedEventArgs e)
        {
            Visualization item  = (Visualization)visAnimGrid.SelectedItem;
            int           index = VisAnimItems.IndexOf(item);

            Debug.Assert(index >= 0 && index < VisAnimItems.Count - 1);
            VisAnimItems.Remove(item);
            VisAnimItems.Insert(index + 1, item);
            visAnimGrid.SelectedIndex = index + 1;
            visAnimGrid.ScrollIntoView(item);

            //RefreshAnim();
        }
        private void PopulateItemLists()
        {
            // Add the animation's visualizations, in order.
            if (mOrigAnim != null)
            {
                for (int i = 0; i < mOrigAnim.Count; i++)
                {
                    int           serial = mOrigAnim[i];
                    Visualization vis    = VisualizationSet.FindVisualizationBySerial(mEditedList,
                                                                                      serial);
                    if (vis != null)
                    {
                        VisAnimItems.Add(vis);
                    }
                    else
                    {
                        // Could happen if the Visualization exists but isn't referenced by
                        // any VisualizationSets.  Shouldn't happen unless the project file
                        // was damaged.  Silently ignore it.
                        Debug.WriteLine("WARNING: unknown vis serial " + serial);
                    }
                }
            }

            // Add all remaining non-animation Visualizations to the "source" set.
            foreach (KeyValuePair <int, VisualizationSet> kvp in mEditedList)
            {
                foreach (Visualization vis in kvp.Value)
                {
                    if (vis is VisualizationAnimation)
                    {
                        // disallow using animations as animation frames
                        continue;
                    }
                    VisSourceItems.Add(vis);
                }
            }

            if (VisSourceItems.Count > 0)
            {
                visSourceGrid.SelectedIndex = 0;
            }
            if (VisAnimItems.Count > 0)
            {
                visAnimGrid.SelectedIndex = 0;
            }
        }
        /// <summary>
        /// Adds an item to the end of the animation list.
        /// </summary>
        /// <remarks>
        /// We could make this an insert or add-at-cursor operation.  This feels a bit more
        /// natural, and works since we're still limited to single-select on the anim list.
        /// The selection should be set to the last item added so we can add repeatedly.
        /// </remarks>
        private void AddSelection()
        {
            if (!IsAddEnabled)
            {
                return;
            }

            for (int i = 0; i < visSourceGrid.SelectedItems.Count; i++)
            {
                Visualization item = (Visualization)visSourceGrid.SelectedItems[i];
                VisAnimItems.Add(item);
            }
            if (visAnimGrid.SelectedIndex < 0)
            {
                visAnimGrid.SelectedIndex = 0;
            }

            RefreshAnim();
        }
        /// <summary>
        /// Removes an item from the animation list.
        /// </summary>
        private void RemoveSelection()
        {
            if (!IsRemoveEnabled)
            {
                return;
            }

            int index = visAnimGrid.SelectedIndex;

            Debug.Assert(index >= 0);
            VisAnimItems.RemoveAt(index);

            if (index == VisAnimItems.Count)
            {
                index--;
            }
            if (index >= 0)
            {
                visAnimGrid.SelectedIndex = index;
            }

            RefreshAnim();
        }