/// <summary> /// Remove an axis from the collection if it is no longer used. /// </summary> /// <param name="sender">The axis that has had its registered /// listeners collection changed.</param> /// <param name="e">Information about the event.</param> private void AxisRegisteredListenersCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { IAxis axis = this.Where(currentAxis => currentAxis.RegisteredListeners == sender).First(); if (e.OldItems != null) { if (!PersistentAxes.Contains(axis) && !SeriesHost.IsUsedByASeries(axis)) { this.Remove(axis); } } }
/// <summary> /// Removes an item from the axes collection but throws an exception /// if a series in the series host is listening to it. /// </summary> /// <param name="index">The index of the item being removed.</param> protected override void RemoveItem(int index) { IAxis axis = this[index]; if (SeriesHost.IsUsedByASeries(axis)) { throw new InvalidOperationException(Resources.SeriesHostAxesCollection_RemoveItem_AxisCannotBeRemovedFromASeriesHostWhenOneOrMoreSeriesAreListeningToIt); } else if (PersistentAxes.Contains(axis)) { throw new InvalidOperationException(Resources.SeriesHostAxesCollection_InvalidAttemptToRemovePermanentAxisFromSeriesHost); } else { base.RemoveItem(index); } }
/// <summary> /// This method synchronizes the collection with the persistent axes /// collection when it is changed. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">Information about the event.</param> public void PersistentAxesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { foreach (IAxis axis in e.NewItems) { if (!this.Contains(axis)) { this.Add(axis); } } } if (e.OldItems != null) { foreach (IAxis axis in e.OldItems) { if (this.Contains(axis) && !SeriesHost.IsUsedByASeries(axis)) { this.Remove(axis); } } } }