private void LayersCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { OnLayersCollectionChanged(e); if (CollectionChanged != null) { CollectionChanged(sender, e); } }
/// <summary> /// Invokes the <c>CollectionChanging</c> event. /// </summary> protected virtual void OnCollectionChanging(NotifyCollectionChangingEventArgs e) { NotifyCollectionChangingEventHandler handler = CollectionChanging; if (handler != null) { handler(this, e); } }
private void RegularGrid_Components_CollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { if (e.Action == NotifyCollectionChangeAction.Add) { var component = (IVariable)e.Item; component.Attributes[CoordinateName] = IsTimeDependent ? "time y x" : "y x"; } isDirty = true; }
protected override void ArgumentsCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { //if a function if (!IsIndependent) { IsAutoSorted = false; } base.ArgumentsCollectionChanged(sender, e); }
private void map_CollectionChanged_Delayed(object sender, NotifyCollectionChangingEventArgs e) { if (IsDisposed || !IsHandleCreated) // must be called before InvokeRequired { return; } map_CollectionChanged(sender, e); }
private void RaiseCollectionChanging(object sender, NotifyCollectionChangingEventArgs e) { OnCollectionChanging(sender, e); var eventHandler = CollectionChanging; if (eventHandler != null) { eventHandler(this, e); } }
void notifyCollectionChanged_CollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { if (!TrackChanges) { return; } if (ExcludedTypes.Contains(sender.GetType())) { return; } NotifyCollectionChangeMemento memento; collectionChangeMementos.TryGetValue(sender, out memento); if (memento == null) { throw new NotSupportedException("CollectionChanged received without CollectionChanging"); } memento.RememberNewValues(sender, e); collectionChangeMementos.Remove(sender); if (currentEditableObjectMemento != null) { if (e.Action == NotifyCollectionChangeAction.Replace) { log.DebugFormat("adding collection change to edit action {0}: {1}:{2} -> {3}:{4}", memento.Action, memento.OldValue ?? "null", memento.OldIndex, memento.NewValue ?? "null", memento.NewIndex); } else { log.DebugFormat("adding collection change to edit action {0}: {1}:{2}", memento.Action, memento.NewValue ?? "null", memento.NewIndex); } } else { if (e.Action == NotifyCollectionChangeAction.Replace) { log.DebugFormat("saving undo for collection change {0}: {1}:{2} -> {3}:{4}", memento.Action, memento.OldValue ?? "null", memento.OldIndex, memento.NewValue ?? "null", memento.NewIndex); } else { log.DebugFormat("saving undo for collection change {0}: {1}:{2}", memento.Action, memento.NewValue ?? "null", memento.NewIndex); } } AddMemento(memento); }
private void FireCollectionChangedEvent(NotifyCollectionChangeAction action, object item, int index, object oldItem = null) { if (CollectionChanged != null) { var args = new NotifyCollectionChangingEventArgs(action, item, index, -1) { OldItem = oldItem }; CollectionChanged(this, args); } }
private bool FireCollectionChangingEvent(NotifyCollectionChangeAction action, T item, int index) { if (CollectionChanging != null) { var args = new NotifyCollectionChangingEventArgs(action, item, index, -1); CollectionChanging(this, args); return(!args.Cancel); } return(true); }
void FeaturesCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { if (sender != features || e.Action == NotifyCollectionChangeAction.Replace) { return; } ThrowExceptionOnModificationWhenInNetCdf(); UpdateGeometry(); }
void ComponentsCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { if (function == null || function.IsEditing) { return; } changing = true; Clear(); ResetBindings(); changing = false; }
protected override void ArgumentsCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { isIndependentDirty = true; // performance optimization //if a function if (Arguments.Count > 0) { IsAutoSorted = false; } base.ArgumentsCollectionChanged(sender, e); }
protected override void SetItemInternal(int index, T item, out bool shouldRaiseEvents) { shouldRaiseEvents = true; int originalIndex = index; if (_filter != null) { originalIndex = _filterCollection.GetKey(index); } if (_notifyCollectionChanging != null) { using (SuspendInternal()) Items[originalIndex] = item; return; } T oldItem = Items[originalIndex]; NotifyCollectionChangingEventArgs args = GetCollectionChangeArgs(NotifyCollectionChangedAction.Replace, oldItem, item, index); OnCollectionChanging(args); if (args.Cancel) { shouldRaiseEvents = false; return; } if (_notifyCollectionChanged != null) { using (SuspendInternal()) Items[originalIndex] = item; return; } Items[originalIndex] = item; if (_filter == null || _filter(item)) { if (_filter != null) { _filterCollection.Values[index] = item; } EventsTracker.AddEvent(args.ChangedEventArgs); } else { if (_filter != null) { _filterCollection.RemoveAt(index); } EventsTracker.AddEvent(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index)); } }
protected override int InsertItemInternal(IList <T> items, int index, T item, bool isAdd, NotificationType notificationType) { if (_filter == null) { return(base.InsertItemInternal(items, index, item, isAdd, GetBaseNotificationType(notificationType))); } var filterCollection = GetFilterCollection(); int originalIndex = index; if (isAdd) { originalIndex = items.Count; } else if (filterCollection.Count != 0) { if (index != 0) { originalIndex = filterCollection.GetKey(index - 1) + 1; } else { originalIndex = filterCollection.GetKey(index); } } NotifyCollectionChangingEventArgs args = null; if (HasChangingFlag(notificationType)) { args = GetCollectionChangeArgs(NotifyCollectionChangedAction.Add, item, index); OnCollectionChanging(args); if (args.Cancel) { return(-1); } } items.Insert(originalIndex, item); if (_isSourceNotifiable) { return(originalIndex); } UpdateFilterItems(filterCollection, originalIndex, 1); if (!_filter(item)) { return(-1); } originalIndex = filterCollection.Add(originalIndex, item); OnCollectionChanged(args?.ChangedEventArgs ?? new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index), notificationType); return(originalIndex); }
private void Functions_CollectionChanging(object sender, NotifyCollectionChangingEventArgs e) { switch (e.Action) { case NotifyCollectionChangeAction.Add: var function = (IFunction)e.Item; if (functions.Contains(function)) { throw new ArgumentOutOfRangeException("Function already registered in the store"); } break; } }
/// <summary> /// Removes all items from the collection. /// </summary> protected virtual void ClearItemsInternal(out bool shouldRaiseEvents) { shouldRaiseEvents = false; NotifyCollectionChangingEventArgs args = GetCollectionChangeArgs(); OnCollectionChanging(args); if (args.Cancel) { return; } Items.Clear(); EventsTracker.AddEvent(args.ChangedEventArgs); shouldRaiseEvents = true; }
protected void LayersCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { // performance if (!created || cloning) { return; } OnLayersCollectionChanged(e); if (CollectionChanged != null) { CollectionChanged(sender, e); } }
/// <summary> /// Listens for changes in reduce array and throws exception if reduction is /// not possible for the given dimension /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Reduce_CollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { //check whether reduced dimensions are bound by offsets for (int i = 0; i < parent.Rank; i++) { if (Reduce[i]) { bool isLimitedToOneIndex = OffsetEnd[i] == OffsetStart[i] || (SelectedIndexes[i] != null && SelectedIndexes[i].Length <= 1); if (!isLimitedToOneIndex) { throw new InvalidOperationException("Reduction not possible because dimension " + i + " is not bound to a single index"); } } } }
public void RemoveAt(int index) { this.OwnerListElement.CheckReadyForUnboundMode(); RadListDataItem radListDataItem = this.useDataView ? this.dataLayer.DataView[index] : this.dataLayer.ListSource[index]; NotifyCollectionChangingEventArgs args = new NotifyCollectionChangingEventArgs(NotifyCollectionChangedAction.Remove, (object)radListDataItem); this.ownerListElement.OnItemsChanging(args); if (args.Cancel) { return; } radListDataItem.DataLayer = (ListDataLayer)null; radListDataItem.Owner = (RadListElement)null; this.dataLayer.ListSource.Remove(radListDataItem); this.ownerListElement.OnItemsChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, (object)radListDataItem)); }
private void tools_CollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { switch (e.Action) { case NotifyCollectionChangeAction.Add: ((IMapTool)e.Item).MapControl = this; break; case NotifyCollectionChangeAction.Remove: ((IMapTool)e.Item).MapControl = null; break; default: break; } }
private void BranchFeaturesOnCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { if (!Equals(sender, branchFeatures)) { return; } var branchFeature = (IBranchFeature)e.Item; switch (e.Action) { case NotifyCollectionChangeAction.Add: branchFeature.Branch = this; break; } }
private void Nodes_CollectionChanging(object sender, NotifyCollectionChangingEventArgs e) { switch (e.Action) { case NotifyCollectionChangeAction.Add: if (sender == Nodes) { var node = (INode)e.Item; if (node.Network != this) { node.Network = this; } } break; } }
public void Insert(int index, RadListDataItem item) { this.OwnerListElement.CheckReadyForUnboundMode(); item.DataLayer = this.dataLayer; item.Owner = this.ownerListElement; NotifyCollectionChangingEventArgs args1 = new NotifyCollectionChangingEventArgs(NotifyCollectionChangedAction.Add, (object)item); this.ownerListElement.OnItemsChanging(args1); if (args1.Cancel) { return; } NotifyCollectionChangedEventArgs args2 = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, (object)item); this.dataLayer.ListSource.Insert(index, item); this.ownerListElement.OnItemsChanged(args2); }
private void OnLayersCollectionChanged(NotifyCollectionChangingEventArgs e) { switch (e.Action) { case NotifyCollectionChangeAction.Add: //set map property for layers being added SetMapInLayer((ILayer)e.Item); ((ILayer)e.Item).RenderRequired = true; break; case NotifyCollectionChangeAction.Remove: RenderRequired = true; //render the group if a layer got removed. break; case NotifyCollectionChangeAction.Replace: throw new NotImplementedException(); } }
void HandleActivitiesCollectionChanged(object sender, NotifyCollectionChangingEventArgs e) { //only local changes...get this in the EventedList... if (sender != activities) { return; } if (e.Action == NotifyCollectionChangeAction.Add) { ((IActivity)e.Item).StatusChanged += HandleActivityStatusChanged; } else if (e.Action == NotifyCollectionChangeAction.Remove) { ((IActivity)e.Item).StatusChanged -= HandleActivityStatusChanged; } }
protected override void InsertItem(int index, T item) { var e1 = new NotifyCollectionChangingEventArgs <T>(NotifyCollectionChangedAction.Add, item, index); OnCollectionChanging(e1); if (!e1.IsEnable) { return; } base.InsertItem(index, item); var e = new NotifyCollectionChangedEventArgs <T>(NotifyCollectionChangedAction.Add, item, index); OnCollectionChanged(e); }
/// <summary> /// Removes the item at the specified index of the collection. /// </summary> /// <param name="index"> /// The zero-based index of the element to remove. /// </param> /// <param name="shouldRaiseEvents"></param> protected virtual void RemoveItemInternal(int index, out bool shouldRaiseEvents) { shouldRaiseEvents = false; T removedItem = Items[index]; NotifyCollectionChangingEventArgs args = GetCollectionChangeArgs(NotifyCollectionChangedAction.Remove, removedItem, index); OnCollectionChanging(args); if (args.Cancel) { return; } Items.RemoveAt(index); EventsTracker.AddEvent(args.ChangedEventArgs); shouldRaiseEvents = true; }
/// <summary> /// Inserts an item into the collection at the specified index. /// </summary> /// <param name="index"> /// The zero-based index at which <paramref name="item" /> should be inserted. /// </param> /// <param name="item"> /// The object to insert. /// </param> /// <param name="isAdd"></param> /// <param name="shouldRaiseEvents"></param> protected virtual int InsertItemInternal(int index, T item, bool isAdd, out bool shouldRaiseEvents) { shouldRaiseEvents = false; NotifyCollectionChangingEventArgs args = GetCollectionChangeArgs(NotifyCollectionChangedAction.Add, item, index); OnCollectionChanging(args); if (args.Cancel) { return(-1); } Items.Insert(index, item); EventsTracker.AddEvent(args.ChangedEventArgs); shouldRaiseEvents = true; return(index); }
protected virtual int InsertItemInternal(IList <T> items, int index, T item, bool isAdd, NotificationType notificationType) { NotifyCollectionChangingEventArgs args = null; if (HasChangingFlag(notificationType)) { args = GetCollectionChangeArgs(NotifyCollectionChangedAction.Add, item, index); OnCollectionChanging(args); if (args.Cancel) { return(-1); } } items.Insert(index, item); OnCollectionChanged(args?.ChangedEventArgs ?? new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index), notificationType); return(index); }
protected virtual bool RemoveItemInternal(IList <T> items, int index, NotificationType notificationType) { var removedItem = items[index]; NotifyCollectionChangingEventArgs args = null; if (HasChangingFlag(notificationType)) { args = GetCollectionChangeArgs(NotifyCollectionChangedAction.Remove, removedItem, index); OnCollectionChanging(args); if (args.Cancel) { return(false); } } items.RemoveAt(index); OnCollectionChanged(args?.ChangedEventArgs ?? new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removedItem, index), notificationType); return(true); }
private void assignments_CollectionChanging(object sender, NotifyCollectionChangingEventArgs e) { // TODO: implement collection changing restrictions switch (e.Action) { case System.Collections.Specialized.NotifyCollectionChangedAction.Add: foreach (StartingLineupAssignment newAssignment in e.NewItems) { if (!newAssignment.Player.Positions.Contains(newAssignment.Position)) { throw new ArgumentException("Player cannot fill this position."); } if (this.Assignments.Where(assignment => assignment.Player == newAssignment.Player).Count() > 0) { throw new ArgumentException("Player cannot be assigned to multiple positions."); } if (this.GetAvailablePositions(newAssignment.Position).Count <= 0) { throw new ArgumentException("No available positions of this type are avilable."); } if (!newAssignment.Player.IsPlaying(this.Date)) { throw new ArgumentException("Player is not playing on the specified date."); } } break; case System.Collections.Specialized.NotifyCollectionChangedAction.Replace: //TODO: throw an exception if player slot is already filled break; case System.Collections.Specialized.NotifyCollectionChangedAction.Move: case System.Collections.Specialized.NotifyCollectionChangedAction.Remove: case System.Collections.Specialized.NotifyCollectionChangedAction.Reset: default: break; } }