Changeset 2424
- Timestamp:
- 10/09/09 16:28:42 (15 years ago)
- Location:
- branches/Mainform refactoring/HeuristicLab.Common/3.2
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Mainform refactoring/HeuristicLab.Common/3.2/HeuristicLab.Common-3.2.csproj
r2371 r2424 78 78 <Reference Include="System.Data" /> 79 79 <Reference Include="System.Xml" /> 80 <Reference Include="WindowsBase"> 81 <RequiredTargetFramework>3.0</RequiredTargetFramework> 82 </Reference> 80 83 </ItemGroup> 81 84 <ItemGroup> 85 <Compile Include="ObservableList.cs" /> 82 86 <Compile Include="DoubleExtensions.cs"> 83 87 <SubType>Code</SubType> -
branches/Mainform refactoring/HeuristicLab.Common/3.2/ObservableCollection.cs
r2323 r2424 23 23 using System.Linq; 24 24 using System.Text; 25 using System.Collections.Specialized; 25 26 26 27 namespace HeuristicLab.Common { 27 public class ObservableCollection<T> : ICollection<T> {28 pr ivateList<T> list;28 public class ObservableCollection<T> : ICollection<T>, INotifyCollectionChanged { 29 protected List<T> list; 29 30 30 31 public ObservableCollection() { … … 33 34 34 35 #region Events 35 public event EventHandler CollectionCleared; 36 protected void FireCollectionCleared() { 37 OnCollectionCleared(); 38 } 39 protected virtual void OnCollectionCleared() { 40 if (CollectionCleared != null) 41 CollectionCleared(this, new EventArgs()); 36 public event NotifyCollectionChangedEventHandler CollectionChanged; 37 38 protected void FireCollectionChanged(NotifyCollectionChangedEventArgs e) { 39 if (CollectionChanged != null) { 40 CollectionChanged(this, e); 41 } 42 42 } 43 43 44 public event EventHandler<EnumerableEventArgs<T>> ItemsAdded; 45 protected void FireItemsAdded(IEnumerable<T> addedItems) { 46 OnItemsAdded(addedItems); 47 } 48 protected virtual void OnItemsAdded(IEnumerable<T> addedItems) { 49 if (ItemsAdded != null) 50 ItemsAdded(this, new EnumerableEventArgs<T>(addedItems)); 44 protected virtual void FireCollectionCleared() { 45 NotifyCollectionChangedEventArgs e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset); 46 FireCollectionChanged( e); 51 47 } 52 48 53 p ublic event EventHandler<EnumerableEventArgs<T>> ItemsRemoved;54 protected void FireItemsRemoved(IEnumerable<T> removedItems) {55 OnItemsRemoved(removedItems);49 protected virtual void FireItemsAdded(IEnumerable<T> addedItems, int index) { 50 NotifyCollectionChangedEventArgs e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, addedItems.ToList(), index); 51 FireCollectionChanged(e); 56 52 } 57 protected virtual void OnItemsRemoved(IEnumerable<T> removedItems) { 58 if (ItemsRemoved != null) 59 ItemsRemoved(this, new EnumerableEventArgs<T>(removedItems)); 53 54 protected virtual void FireItemsRemoved(IEnumerable<T> removedItems) { 55 NotifyCollectionChangedEventArgs e = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, removedItems.ToList()); 56 FireCollectionChanged(e); 60 57 } 61 58 #endregion … … 63 60 #region ICollection<T> Members 64 61 public void Add(T item) { 62 int index = this.list.Count - 1; 65 63 this.list.Add(item); 66 FireItemsAdded(new List<T> { item } );64 FireItemsAdded(new List<T> { item }, index); 67 65 } 68 66 69 67 public void AddRange(IEnumerable<T> items) { 68 int index = this.list.Count - 1; 70 69 this.list.AddRange(items); 71 FireItemsAdded(items );70 FireItemsAdded(items, index); 72 71 } 73 72 … … 125 124 126 125 #endregion 126 127 127 128 } 128 129 }
Note: See TracChangeset
for help on using the changeset viewer.