private void Gates_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { Gate gate; switch (e.Action) { case NotifyCollectionChangedAction.Add: int addIndex = e.NewStartingIndex; foreach (object item in e.NewItems) { gate = item as Gate; if (gate != null) { RegisterRefModel gateRow = _model.GetRefFromOffset(addIndex); Gates.Insert(addIndex, new GateVM(_model, gateRow, _column)); for (int i = addIndex + 1; i < _gates.Count; i++) { _gates[i].UpdateRow(i); } if (_gates.Count == 2) { _gates[0].UpdateDeleteRowCommand(true); _gates[1].UpdateDeleteRowCommand(true); } } } break; case NotifyCollectionChangedAction.Replace: foreach (object item in e.NewItems) { gate = item as Gate; for (int i = gate.Begin; i <= gate.End; i++) { Gates[i].Refresh(); } } break; case NotifyCollectionChangedAction.Remove: int oldRow = e.OldStartingIndex; foreach (object item in e.OldItems) { if (item is Gate) { Gates.RemoveAt(oldRow); for (int i = oldRow; i < _gates.Count; i++) { _gates[i].UpdateRow(i); } if (_gates.Count == 1) { _gates[0].UpdateDeleteRowCommand(false); } } } break; } OnPropertyChanged("ScaleCenterY"); }