Changeset 2620
- Timestamp:
- 01/11/10 03:55:51 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Collections/3.3
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Collections/3.3/IObservableCollection.cs
r2618 r2620 24 24 using System.Linq; 25 25 using System.Text; 26 using System.ComponentModel; 26 27 27 28 namespace HeuristicLab.Collections { 28 public interface IObservableCollection<T> : ICollection<T> {29 public interface IObservableCollection<T> : ICollection<T>, INotifyPropertyChanged { 29 30 event CollectionItemsChangedEventHandler<T> ItemsAdded; 30 31 event CollectionItemsChangedEventHandler<T> ItemsRemoved; -
trunk/sources/HeuristicLab.Collections/3.3/IObservableDictionary.cs
r2618 r2620 24 24 using System.Linq; 25 25 using System.Text; 26 using System.ComponentModel; 26 27 27 28 namespace HeuristicLab.Collections { 28 public interface IObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue> {29 public interface IObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, INotifyPropertyChanged { 29 30 event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsAdded; 30 31 event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsRemoved; -
trunk/sources/HeuristicLab.Collections/3.3/IObservableKeyedCollection.cs
r2618 r2620 24 24 using System.Linq; 25 25 using System.Text; 26 using System.ComponentModel; 26 27 27 28 namespace HeuristicLab.Collections { 28 public interface IObservableKeyedCollection<TKey, TItem> : ICollection<TItem> {29 public interface IObservableKeyedCollection<TKey, TItem> : ICollection<TItem>, INotifyPropertyChanged { 29 30 TItem this[TKey key] { get; } 30 31 -
trunk/sources/HeuristicLab.Collections/3.3/IObservableList.cs
r2618 r2620 24 24 using System.Linq; 25 25 using System.Text; 26 using System.ComponentModel; 26 27 27 28 namespace HeuristicLab.Collections { 28 public interface IObservableList<T> : IList<T> {29 public interface IObservableList<T> : IList<T>, INotifyPropertyChanged { 29 30 event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsAdded; 30 31 event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved; -
trunk/sources/HeuristicLab.Collections/3.3/ObservableCollection.cs
r2618 r2620 24 24 using System.Collections.Generic; 25 25 using System.Collections.ObjectModel; 26 using System.ComponentModel; 26 27 using System.Linq; 27 28 using System.Text; … … 37 38 public int Capacity { 38 39 get { return list.Capacity; } 39 set { list.Capacity = value; } 40 set { 41 if (list.Capacity != value) { 42 list.Capacity = value; 43 OnPropertyChanged("Capacity"); 44 } 45 } 40 46 } 41 47 public int Count { … … 82 88 #region Manipulation 83 89 public void Add(T item) { 90 int capacity = list.Capacity; 84 91 list.Add(item); 92 if (list.Capacity != capacity) 93 OnPropertyChanged("Capacity"); 94 OnPropertyChanged("Count"); 85 95 OnItemsAdded(new T[] { item }); 86 96 } 87 97 public void AddRange(IEnumerable<T> collection) { 98 int capacity = list.Capacity; 99 int count = list.Count; 88 100 list.AddRange(collection); 89 OnItemsAdded(collection); 101 if (list.Count != count) { 102 if (list.Capacity != capacity) 103 OnPropertyChanged("Capacity"); 104 OnPropertyChanged("Count"); 105 OnItemsAdded(collection); 106 } 90 107 } 91 108 92 109 public bool Remove(T item) { 93 110 if (list.Remove(item)) { 111 OnPropertyChanged("Count"); 94 112 OnItemsRemoved(new T[] { item }); 95 113 return true; … … 104 122 items.Add(item); 105 123 } 106 if (items.Count > 0) 124 if (items.Count > 0) { 125 OnPropertyChanged("Count"); 107 126 OnItemsRemoved(items); 127 } 108 128 } 109 129 public int RemoveAll(Predicate<T> match) { 110 130 List<T> items = list.FindAll(match); 111 int result = list.RemoveAll(match); 112 OnItemsRemoved(items); 131 int result = 0; 132 if (items.Count > 0) { 133 result = list.RemoveAll(match); 134 OnPropertyChanged("Count"); 135 OnItemsRemoved(items); 136 } 113 137 return result; 114 138 } 115 139 116 140 public void Clear() { 117 T[] items = list.ToArray(); 118 list.Clear(); 119 OnCollectionReset(new T[0], items); 141 if (list.Count > 0) { 142 T[] items = list.ToArray(); 143 list.Clear(); 144 OnPropertyChanged("Count"); 145 OnCollectionReset(new T[0], items); 146 } 120 147 } 121 148 #endregion … … 156 183 #region Helpers 157 184 public void TrimExcess() { 185 int capacity = list.Capacity; 158 186 list.TrimExcess(); 187 if (list.Capacity != capacity) 188 OnPropertyChanged("Capacity"); 159 189 } 160 190 #endregion … … 181 211 CollectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems)); 182 212 } 213 214 [field: NonSerialized] 215 public event PropertyChangedEventHandler PropertyChanged; 216 protected virtual void OnPropertyChanged(string propertyName) { 217 if (PropertyChanged != null) 218 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 219 } 183 220 #endregion 184 221 } -
trunk/sources/HeuristicLab.Collections/3.3/ObservableDictionary.cs
r2618 r2620 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.ComponentModel; 25 26 using System.Linq; 26 27 using System.Text; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System.Runtime.Serialization;29 29 30 30 namespace HeuristicLab.Collections { … … 110 110 public void Add(TKey key, TValue value) { 111 111 dict.Add(key, value); 112 OnPropertyChanged("Item[]"); 113 OnPropertyChanged("Keys"); 114 OnPropertyChanged("Values"); 115 OnPropertyChanged("Count"); 112 116 OnItemsAdded(new KeyValuePair<TKey, TValue>[] { new KeyValuePair<TKey, TValue>(key, value) }); 113 117 } 114 118 void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item) { 115 119 ((ICollection<KeyValuePair<TKey, TValue>>)dict).Add(item); 120 OnPropertyChanged("Item[]"); 121 OnPropertyChanged("Keys"); 122 OnPropertyChanged("Values"); 123 OnPropertyChanged("Count"); 116 124 OnItemsAdded(new KeyValuePair<TKey, TValue>[] { item }); 117 125 } … … 121 129 if (dict.TryGetValue(key, out value)) { 122 130 dict.Remove(key); 131 OnPropertyChanged("Item[]"); 132 OnPropertyChanged("Keys"); 133 OnPropertyChanged("Values"); 134 OnPropertyChanged("Count"); 123 135 OnItemsRemoved(new KeyValuePair<TKey, TValue>[] { new KeyValuePair<TKey, TValue>(key, value) }); 124 136 return true; … … 128 140 bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item) { 129 141 if (((ICollection<KeyValuePair<TKey, TValue>>)dict).Remove(item)) { 142 OnPropertyChanged("Item[]"); 143 OnPropertyChanged("Keys"); 144 OnPropertyChanged("Values"); 145 OnPropertyChanged("Count"); 130 146 OnItemsRemoved(new KeyValuePair<TKey, TValue>[] { item }); 131 147 return true; … … 135 151 136 152 public void Clear() { 137 KeyValuePair<TKey, TValue>[] items = dict.ToArray(); 138 dict.Clear(); 139 OnCollectionReset(new KeyValuePair<TKey, TValue>[0], items); 153 if (dict.Count > 0) { 154 KeyValuePair<TKey, TValue>[] items = dict.ToArray(); 155 dict.Clear(); 156 OnPropertyChanged("Item[]"); 157 OnPropertyChanged("Keys"); 158 OnPropertyChanged("Values"); 159 OnPropertyChanged("Count"); 160 OnCollectionReset(new KeyValuePair<TKey, TValue>[0], items); 161 } 140 162 } 141 163 #endregion … … 190 212 CollectionReset(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems)); 191 213 } 214 215 [field: NonSerialized] 216 public event PropertyChangedEventHandler PropertyChanged; 217 protected virtual void OnPropertyChanged(string propertyName) { 218 if (PropertyChanged != null) 219 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 220 } 192 221 #endregion 193 222 } -
trunk/sources/HeuristicLab.Collections/3.3/ObservableKeyedCollectionBase.cs
r2618 r2620 24 24 using System.Collections.Generic; 25 25 using System.Collections.ObjectModel; 26 using System.ComponentModel; 26 27 using System.Linq; 27 28 using System.Text; … … 93 94 } 94 95 } 95 if (!oldKeyFound) throw new ArgumentException(" item not found");96 if (!oldKeyFound) throw new ArgumentException("Item not found"); 96 97 dict.Remove(oldKey); 97 98 dict.Add(GetKeyForItem(item), item); 99 OnPropertyChanged("Item[]"); 98 100 OnItemsReplaced(new TItem[] { item }, new TItem[] { item }); 99 101 } … … 139 141 public void Add(TItem item) { 140 142 dict.Add(GetKeyForItem(item), item); 143 OnPropertyChanged("Item[]"); 144 OnPropertyChanged("Count"); 141 145 OnItemsAdded(new TItem[] { item }); 142 146 } 143 147 public void AddRange(IEnumerable<TItem> collection) { 144 148 if (collection == null) throw new ArgumentNullException(); 145 foreach (TItem item in collection) 149 bool empty = true; 150 foreach (TItem item in collection) { 146 151 dict.Add(GetKeyForItem(item), item); 147 OnItemsAdded(collection); 152 empty = false; 153 } 154 if (!empty) { 155 OnPropertyChanged("Item[]"); 156 OnPropertyChanged("Count"); 157 OnItemsAdded(collection); 158 } 148 159 } 149 160 … … 152 163 if (TryGetValue(key, out item)) { 153 164 dict.Remove(key); 165 OnPropertyChanged("Item[]"); 166 OnPropertyChanged("Count"); 154 167 OnItemsRemoved(new TItem[] { item }); 155 168 return true; … … 159 172 public bool Remove(TItem item) { 160 173 if (dict.Remove(GetKeyForItem(item))) { 174 OnPropertyChanged("Item[]"); 175 OnPropertyChanged("Count"); 161 176 OnItemsRemoved(new TItem[] { item }); 162 177 return true; … … 171 186 items.Add(item); 172 187 } 173 if (items.Count > 0) 188 if (items.Count > 0) { 189 OnPropertyChanged("Item[]"); 190 OnPropertyChanged("Count"); 174 191 OnItemsRemoved(items); 192 } 175 193 } 176 194 public int RemoveAll(Predicate<TItem> match) { … … 181 199 182 200 public void Clear() { 183 TItem[] items = dict.Values.ToArray(); 184 dict.Clear(); 185 OnCollectionReset(new TItem[0], items); 201 if (dict.Count > 0) { 202 TItem[] items = dict.Values.ToArray(); 203 dict.Clear(); 204 OnPropertyChanged("Item[]"); 205 OnPropertyChanged("Count"); 206 OnCollectionReset(new TItem[0], items); 207 } 186 208 } 187 209 #endregion … … 257 279 CollectionReset(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems)); 258 280 } 281 282 [field: NonSerialized] 283 public event PropertyChangedEventHandler PropertyChanged; 284 protected virtual void OnPropertyChanged(string propertyName) { 285 if (PropertyChanged != null) 286 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 287 } 259 288 #endregion 260 289 } -
trunk/sources/HeuristicLab.Collections/3.3/ObservableList.cs
r2618 r2620 24 24 using System.Collections.Generic; 25 25 using System.Collections.ObjectModel; 26 using System.ComponentModel; 26 27 using System.Linq; 27 28 using System.Text; … … 37 38 public int Capacity { 38 39 get { return list.Capacity; } 39 set { list.Capacity = value; } 40 set { 41 if (list.Capacity != value) { 42 list.Capacity = value; 43 OnPropertyChanged("Capacity"); 44 } 45 } 40 46 } 41 47 public int Count { … … 52 58 set { 53 59 T item = list[index]; 54 list[index] = value; 55 OnItemsReplaced(new IndexedItem<T>[] { new IndexedItem<T>(index, value) }, new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 60 if (!item.Equals(value)) { 61 list[index] = value; 62 OnItemsReplaced(new IndexedItem<T>[] { new IndexedItem<T>(index, value) }, new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 63 OnPropertyChanged("Item[]"); 64 } 56 65 } 57 66 } … … 147 156 #region Manipulation 148 157 public void Add(T item) { 158 int capacity = list.Capacity; 149 159 list.Add(item); 160 if (list.Capacity != capacity) 161 OnPropertyChanged("Capacity"); 162 OnPropertyChanged("Item[]"); 163 OnPropertyChanged("Count"); 150 164 OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(list.Count - 1, item) }); 151 165 } 152 166 public void AddRange(IEnumerable<T> collection) { 167 int capacity = list.Capacity; 153 168 int index = list.Count; 154 169 list.AddRange(collection); … … 158 173 index++; 159 174 } 160 OnItemsAdded(items); 175 if (items.Count > 0) { 176 if (list.Capacity != capacity) 177 OnPropertyChanged("Capacity"); 178 OnPropertyChanged("Item[]"); 179 OnPropertyChanged("Count"); 180 OnItemsAdded(items); 181 } 161 182 } 162 183 163 184 public void Insert(int index, T item) { 185 int capacity = list.Capacity; 164 186 list.Insert(index, item); 187 if (list.Capacity != capacity) 188 OnPropertyChanged("Capacity"); 189 OnPropertyChanged("Item[]"); 190 OnPropertyChanged("Count"); 165 191 OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 166 192 } 167 193 public void InsertRange(int index, IEnumerable<T> collection) { 194 int capacity = list.Capacity; 168 195 list.InsertRange(index, collection); 169 196 List<IndexedItem<T>> items = new List<IndexedItem<T>>(); … … 172 199 index++; 173 200 } 174 OnItemsAdded(items); 201 if (items.Count > 0) { 202 if (list.Capacity != capacity) 203 OnPropertyChanged("Capacity"); 204 OnPropertyChanged("Item[]"); 205 OnPropertyChanged("Count"); 206 OnItemsAdded(items); 207 } 175 208 } 176 209 … … 179 212 if (index != -1) { 180 213 list.RemoveAt(index); 214 OnPropertyChanged("Item[]"); 215 OnPropertyChanged("Count"); 181 216 OnItemsRemoved(new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 182 217 return true; … … 191 226 items.Add(new IndexedItem<T>(i, list[i])); 192 227 } 193 int result = list.RemoveAll(match); 194 OnItemsRemoved(items); 228 int result = 0; 229 if (items.Count > 0) { 230 result = list.RemoveAll(match); 231 OnPropertyChanged("Item[]"); 232 OnPropertyChanged("Count"); 233 OnItemsRemoved(items); 234 } 195 235 return result; 196 236 } … … 198 238 T item = list[index]; 199 239 list.RemoveAt(index); 240 OnPropertyChanged("Item[]"); 241 OnPropertyChanged("Count"); 200 242 OnItemsRemoved(new IndexedItem<T>[] { new IndexedItem<T>(index, item) }); 201 243 } 202 244 public void RemoveRange(int index, int count) { 203 IndexedItem<T>[] items = GetIndexedItems(index, count); 204 list.RemoveRange(index, count); 205 OnItemsRemoved(items); 245 if (count > 0) { 246 IndexedItem<T>[] items = GetIndexedItems(index, count); 247 list.RemoveRange(index, count); 248 OnPropertyChanged("Item[]"); 249 OnPropertyChanged("Count"); 250 OnItemsRemoved(items); 251 } 206 252 } 207 253 208 254 public void Clear() { 209 IndexedItem<T>[] items = GetIndexedItems(); 210 list.Clear(); 211 OnCollectionReset(new IndexedItem<T>[0], items); 255 if (list.Count > 0) { 256 IndexedItem<T>[] items = GetIndexedItems(); 257 list.Clear(); 258 OnPropertyChanged("Item[]"); 259 OnPropertyChanged("Count"); 260 OnCollectionReset(new IndexedItem<T>[0], items); 261 } 212 262 } 213 263 214 264 public void Reverse() { 215 IndexedItem<T>[] oldItems = GetIndexedItems(); 216 list.Reverse(); 217 OnItemsMoved(GetIndexedItems(), oldItems); 265 if (list.Count > 1) { 266 IndexedItem<T>[] oldItems = GetIndexedItems(); 267 list.Reverse(); 268 OnPropertyChanged("Item[]"); 269 OnItemsMoved(GetIndexedItems(), oldItems); 270 } 218 271 } 219 272 public void Reverse(int index, int count) { 220 IndexedItem<T>[] oldItems = GetIndexedItems(index, count); 221 list.Reverse(index, count); 222 OnItemsMoved(GetIndexedItems(index, count), oldItems); 273 if (count > 1) { 274 IndexedItem<T>[] oldItems = GetIndexedItems(index, count); 275 list.Reverse(index, count); 276 OnPropertyChanged("Item[]"); 277 OnItemsMoved(GetIndexedItems(index, count), oldItems); 278 } 223 279 } 224 280 225 281 public void Sort() { 226 IndexedItem<T>[] oldItems = GetIndexedItems(); 227 list.Sort(); 228 OnItemsMoved(GetIndexedItems(), oldItems); 282 if (list.Count > 1) { 283 IndexedItem<T>[] oldItems = GetIndexedItems(); 284 list.Sort(); 285 OnPropertyChanged("Item[]"); 286 OnItemsMoved(GetIndexedItems(), oldItems); 287 } 229 288 } 230 289 public void Sort(Comparison<T> comparison) { 231 IndexedItem<T>[] oldItems = GetIndexedItems(); 232 list.Sort(comparison); 233 OnItemsMoved(GetIndexedItems(), oldItems); 290 if (list.Count > 1) { 291 IndexedItem<T>[] oldItems = GetIndexedItems(); 292 list.Sort(comparison); 293 OnPropertyChanged("Item[]"); 294 OnItemsMoved(GetIndexedItems(), oldItems); 295 } 234 296 } 235 297 public void Sort(IComparer<T> comparer) { 236 IndexedItem<T>[] oldItems = GetIndexedItems(); 237 list.Sort(comparer); 238 OnItemsMoved(GetIndexedItems(), oldItems); 298 if (list.Count > 1) { 299 IndexedItem<T>[] oldItems = GetIndexedItems(); 300 list.Sort(comparer); 301 OnPropertyChanged("Item[]"); 302 OnItemsMoved(GetIndexedItems(), oldItems); 303 } 239 304 } 240 305 public void Sort(int index, int count, IComparer<T> comparer) { 241 IndexedItem<T>[] oldItems = GetIndexedItems(index, count); 242 list.Sort(index, count, comparer); 243 OnItemsMoved(GetIndexedItems(index, count), oldItems); 306 if (list.Count > 1) { 307 IndexedItem<T>[] oldItems = GetIndexedItems(index, count); 308 list.Sort(index, count, comparer); 309 OnPropertyChanged("Item[]"); 310 OnItemsMoved(GetIndexedItems(index, count), oldItems); 311 } 244 312 } 245 313 #endregion … … 283 351 #region Helpers 284 352 public void TrimExcess() { 353 int capacity = list.Capacity; 285 354 list.TrimExcess(); 355 if (list.Capacity != capacity) 356 OnPropertyChanged("Capacity"); 286 357 } 287 358 #endregion … … 321 392 if (CollectionReset != null) 322 393 CollectionReset(this, new CollectionItemsChangedEventArgs<IndexedItem<T>>(items, oldItems)); 394 } 395 396 [field: NonSerialized] 397 public event PropertyChangedEventHandler PropertyChanged; 398 protected virtual void OnPropertyChanged(string propertyName) { 399 if (PropertyChanged != null) 400 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 323 401 } 324 402 #endregion -
trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableCollection.cs
r2618 r2620 24 24 using System.Collections.Generic; 25 25 using System.Collections.ObjectModel; 26 using System.ComponentModel; 26 27 using System.Linq; 27 28 using System.Text; … … 50 51 collection.ItemsRemoved += new CollectionItemsChangedEventHandler<T>(collection_ItemsRemoved); 51 52 collection.CollectionReset += new CollectionItemsChangedEventHandler<T>(collection_CollectionReset); 53 collection.PropertyChanged += new PropertyChangedEventHandler(collection_PropertyChanged); 52 54 } 53 55 #endregion … … 110 112 } 111 113 114 [field: NonSerialized] 115 public event PropertyChangedEventHandler PropertyChanged; 116 protected virtual void OnPropertyChanged(string propertyName) { 117 if (PropertyChanged != null) 118 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 119 } 120 112 121 private void collection_ItemsAdded(object sender, CollectionItemsChangedEventArgs<T> e) { 113 122 OnItemsAdded(e.Items); … … 119 128 OnCollectionReset(e.Items, e.OldItems); 120 129 } 130 private void collection_PropertyChanged(object sender, PropertyChangedEventArgs e) { 131 if (e.PropertyName.Equals("Count")) 132 OnPropertyChanged(e.PropertyName); 133 } 121 134 #endregion 122 135 } -
trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableDictionary.cs
r2618 r2620 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.ComponentModel; 25 26 using System.Linq; 26 27 using System.Text; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System.Runtime.Serialization;29 29 30 30 namespace HeuristicLab.Collections { … … 65 65 dict.ItemsReplaced += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_ItemsReplaced); 66 66 dict.CollectionReset += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_CollectionReset); 67 dict.PropertyChanged += new PropertyChangedEventHandler(dict_PropertyChanged); 67 68 } 68 69 #endregion … … 145 146 } 146 147 148 [field: NonSerialized] 149 public event PropertyChangedEventHandler PropertyChanged; 150 protected virtual void OnPropertyChanged(string propertyName) { 151 if (PropertyChanged != null) 152 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 153 } 154 147 155 private void dict_ItemsAdded(object sender, CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>> e) { 148 156 OnItemsAdded(e.Items); … … 157 165 OnCollectionReset(e.Items, e.OldItems); 158 166 } 167 private void dict_PropertyChanged(object sender, PropertyChangedEventArgs e) { 168 if (e.PropertyName.Equals("Item[]") || e.PropertyName.Equals("Keys") || e.PropertyName.Equals("Values") || e.PropertyName.Equals("Count")) 169 OnPropertyChanged(e.PropertyName); 170 } 159 171 #endregion 160 172 } -
trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableKeyedCollection.cs
r2618 r2620 24 24 using System.Collections.Generic; 25 25 using System.Collections.ObjectModel; 26 using System.ComponentModel; 26 27 using System.Linq; 27 28 using System.Text; … … 57 58 collection.ItemsReplaced += new CollectionItemsChangedEventHandler<TItem>(collection_ItemsReplaced); 58 59 collection.CollectionReset += new CollectionItemsChangedEventHandler<TItem>(collection_CollectionReset); 60 collection.PropertyChanged += new PropertyChangedEventHandler(collection_PropertyChanged); 59 61 } 60 62 #endregion … … 131 133 } 132 134 135 [field: NonSerialized] 136 public event PropertyChangedEventHandler PropertyChanged; 137 protected virtual void OnPropertyChanged(string propertyName) { 138 if (PropertyChanged != null) 139 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 140 } 141 133 142 private void collection_ItemsAdded(object sender, CollectionItemsChangedEventArgs<TItem> e) { 134 143 OnItemsAdded(e.Items); … … 143 152 OnCollectionReset(e.Items, e.OldItems); 144 153 } 154 private void collection_PropertyChanged(object sender, PropertyChangedEventArgs e) { 155 if (e.PropertyName.Equals("Item[]") || e.PropertyName.Equals("Count")) 156 OnPropertyChanged(e.PropertyName); 157 } 145 158 #endregion 146 159 } -
trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableList.cs
r2618 r2620 24 24 using System.Collections.Generic; 25 25 using System.Collections.ObjectModel; 26 using System.ComponentModel; 26 27 using System.Linq; 27 28 using System.Text; … … 60 61 list.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsMoved); 61 62 list.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_CollectionReset); 63 list.PropertyChanged += new PropertyChangedEventHandler(list_PropertyChanged); 62 64 } 63 65 #endregion … … 145 147 } 146 148 149 [field: NonSerialized] 150 public event PropertyChangedEventHandler PropertyChanged; 151 protected virtual void OnPropertyChanged(string propertyName) { 152 if (PropertyChanged != null) 153 PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 154 } 155 147 156 private void list_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) { 148 157 OnItemsAdded(e.Items); … … 160 169 OnCollectionReset(e.Items, e.OldItems); 161 170 } 171 private void list_PropertyChanged(object sender, PropertyChangedEventArgs e) { 172 if (e.PropertyName.Equals("Item[]") || e.PropertyName.Equals("Count")) 173 OnPropertyChanged(e.PropertyName); 174 } 162 175 #endregion 163 176 }
Note: See TracChangeset
for help on using the changeset viewer.