Exemplo n.º 1
0
        private void DoUpdate(ISortedChangeSet <TObject, TKey> updates, IObservableCollection <TObject> list)
        {
            updates.ForEach(update =>
            {
                switch (update.Reason)
                {
                case ChangeReason.Add:
                    list.Insert(update.CurrentIndex, update.Current);
                    break;

                case ChangeReason.Remove:
                    list.RemoveAt(update.CurrentIndex);
                    break;

                case ChangeReason.Moved:
                    list.Move(update.PreviousIndex, update.CurrentIndex);
                    break;

                case ChangeReason.Update:
                    {
                        list.RemoveAt(update.PreviousIndex);
                        list.Insert(update.CurrentIndex, update.Current);
                    }
                    break;
                }
            });
        }
Exemplo n.º 2
0
        private void DoUpdate(ISortedChangeSet <TObject, TKey> updates, IObservableCollection <TObject> list)
        {
            foreach (var update in updates)
            {
                switch (update.Reason)
                {
                case ChangeReason.Add:
                    list.Insert(update.CurrentIndex, update.Current);
                    break;

                case ChangeReason.Remove:
                    list.RemoveAt(update.CurrentIndex);
                    break;

                case ChangeReason.Moved:
                    list.Move(update.PreviousIndex, update.CurrentIndex);
                    break;

                case ChangeReason.Update:
                    if (update.PreviousIndex != update.CurrentIndex)
                    {
                        list.RemoveAt(update.PreviousIndex);
                        list.Insert(update.CurrentIndex, update.Current);
                    }
                    else
                    {
                        list.Replace(update.Previous.Value, update.Current);
                    }

                    break;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// in place sort an <see cref="IObservableCollection{T}"/> utilizing an <see cref="IComparer{T}"/>
        /// </summary>
        /// <remarks>
        /// will undo selection, when collection is bound for example to a ListBox
        /// </remarks>
        public static void Sort <T>(this IObservableCollection <T> collection, IComparer <T> comparer)
        {
            var sorted = collection.OrderBy(x => x, comparer).ToList();

            for (var i = 0; i < sorted.Count; i++)
            {
                collection.Move(collection.IndexOf(sorted[i]), i);
            }
        }
 /// <summary>
 /// Move o item de uma posição para outra.
 /// </summary>
 /// <param name="oldIndex">Indice antigo</param>
 /// <param name="newIndex">Novo indice.</param>
 public void Move(int oldIndex, int newIndex)
 {
     _source.Move(oldIndex, newIndex);
 }
 /// <summary>
 /// Novo o item.
 /// </summary>
 /// <param name="oldIndex"></param>
 /// <param name="newIndex"></param>
 public void Move(int oldIndex, int newIndex)
 {
     _source.Move(_indexes[oldIndex], _indexes[newIndex]);
 }