#region CPL License /* Nuclex Framework Copyright (C) 2002-2007 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion using System; using System.Collections.Generic; using System.Collections.ObjectModel; namespace Nuclex.Support.Collections { /// Collection which fires events when items are added or removed public class ObservableCollection : AcquiringCollection { /// Raised when an item has been added to the collection public event EventHandler> ItemAdded; /// Raised when an item is removed from the collection public event EventHandler> ItemRemoved; /// Raised the collection is about to be cleared public event EventHandler Clearing; /// /// Initializes a new instance of the ObservableCollection class that is empty. /// public ObservableCollection() : base() { } /// /// Initializes a new instance of the ObservableCollection class as a wrapper /// for the specified list. /// /// The list that is wrapped by the new collection. /// List is null. public ObservableCollection(IList list) : base(list) { } /// Fires the 'ItemAdded' event /// Item that has been added to the collection protected override void OnAdded(ItemType item) { if(ItemAdded != null) ItemAdded(this, new ItemEventArgs(item)); } /// Fires the 'ItemRemoved' event /// Item that has been removed from the collection protected override void OnRemoved(ItemType item) { if(ItemRemoved != null) ItemRemoved(this, new ItemEventArgs(item)); } /// Fires the 'Clearing' event protected override void OnClearing() { if(Clearing != null) Clearing(this, EventArgs.Empty); } } } // namespace Nuclex.Support.Collections