Exemplo n.º 1
0
 int IndexOf(object item)
 {
     if (Grouping)
     {
         return(RootGroup.IndexOfSubtree(item));
     }
     else
     {
         return(ActiveList.IndexOf(item));
     }
 }
Exemplo n.º 2
0
        public override object AddNew()
        {
            ThrowIfDeferred();

            if (ItemConstructor == null)
            {
                throw new InvalidOperationException("The underlying collection does not support adding new items");
            }

            if (SourceCollection.IsFixedSize)
            {
                throw new InvalidOperationException("The source collection is of fixed size");
            }

            // If there's an existing AddNew or Edit, we commit it. Commit the edit first because
            // we're not allowed CommitNew if we're in the middle of an edit.
            if (IsEditingItem)
            {
                CommitEdit();
            }
            if (IsAddingNew)
            {
                CommitNew();
            }

            var newObject = ItemConstructor.Invoke(null);

            // FIXME: I need to check the ordering on the events when the source is INCC
            CurrentAddItem = newObject;
            IsAddingNew    = true;
            if (Grouping)
            {
                RootGroup.AddItem(newObject, false, SourceCollection);
                HandleRootGroupCollectionChanged(RootGroup, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newObject, RootGroup.IndexOfSubtree(newObject)));
            }
            AddToSourceCollection(newObject);
            MoveCurrentTo(newObject);

            if (newObject is IEditableObject)
            {
                ((IEditableObject)newObject).BeginEdit();
            }

            UpdateCanAddNewAndRemove();
            return(newObject);
        }