private void ResetViews()
        {
            using (new SourceAccess(this))
            {
                int currentIndex = this.Zoombox.ViewStackIndex;
                this.IsResettingViews = true;
                try
                {
                    this.Clear();
                    foreach (object item in _source)
                    {
                        ZoomboxView view = ZoomboxViewStack.GetViewFromSourceItem(item);
                        this.Add(view);
                    }

                    currentIndex = Math.Min(Math.Max(0, currentIndex), this.Count - 1);

                    this.Zoombox.ViewStackIndex = currentIndex;
                    this.Zoombox.SetCurrentViewIndex(currentIndex);
                    this.Zoombox.RefocusView();
                }
                finally
                {
                    this.IsResettingViews = false;
                }
            }
        }
        private void MoveViews(int oldIndex, int newIndex, IList movedItems)
        {
            using (new SourceAccess(this))
            {
                int currentIndex   = this.Zoombox.ViewStackIndex;
                int indexAfterMove = currentIndex;

                // adjust the current index, if it was affected by the move
                if (!((oldIndex < currentIndex && newIndex < currentIndex) ||
                      (oldIndex > currentIndex && newIndex > currentIndex)))
                {
                    if (currentIndex >= oldIndex && currentIndex < oldIndex + movedItems.Count)
                    {
                        indexAfterMove += newIndex - oldIndex;
                    }
                    else if (currentIndex >= newIndex)
                    {
                        indexAfterMove += movedItems.Count;
                    }
                }

                this.IsMovingViews = true;
                try
                {
                    for (int i = 0; i < movedItems.Count; i++)
                    {
                        this.RemoveAt(oldIndex);
                    }
                    for (int i = 0; i < movedItems.Count; i++)
                    {
                        this.Insert(newIndex + i, ZoomboxViewStack.GetViewFromSourceItem(movedItems[i]));
                    }
                    if (indexAfterMove != currentIndex)
                    {
                        this.Zoombox.ViewStackIndex = indexAfterMove;
                        this.Zoombox.SetCurrentViewIndex(indexAfterMove);
                    }
                }
                finally
                {
                    this.IsMovingViews = false;
                }
            }
        }
 private void InsertViews(int index, IList newItems)
 {
     using (new SourceAccess(this))
     {
         foreach (object item in newItems)
         {
             ZoomboxView view = ZoomboxViewStack.GetViewFromSourceItem(item);
             if (index >= this.Count)
             {
                 this.Add(view);
             }
             else
             {
                 this.Insert(index, view);
             }
             index++;
         }
     }
 }
 public SourceAccess(ZoomboxViewStack viewStack)
 {
     _viewStack = viewStack;
     _viewStack.IsChangeFromSource = true;
 }