System.Windows.Data.ListCollectionView.AddNew C# (CSharp) Method

AddNew() public method

public AddNew ( ) : object
return object
		public override object AddNew ()
		{
			if (((IDeferRefresh) this).DeferLevel != 0)
				throw new InvalidOperationException ("Cannot add a new item while refresh is deferred");

			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);
			AddToSourceCollection (newObject);
			MoveCurrentTo (newObject);

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

			UpdateCanAddNewAndRemove ();
			return newObject;
		}