Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2620


Ignore:
Timestamp:
01/11/10 03:55:51 (14 years ago)
Author:
swagner
Message:

Implemented INotifyPropertyChanged in all observable collections (#819)

Location:
trunk/sources/HeuristicLab.Collections/3.3
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Collections/3.3/IObservableCollection.cs

    r2618 r2620  
    2424using System.Linq;
    2525using System.Text;
     26using System.ComponentModel;
    2627
    2728namespace HeuristicLab.Collections {
    28   public interface IObservableCollection<T> : ICollection<T> {
     29  public interface IObservableCollection<T> : ICollection<T>, INotifyPropertyChanged {
    2930    event CollectionItemsChangedEventHandler<T> ItemsAdded;
    3031    event CollectionItemsChangedEventHandler<T> ItemsRemoved;
  • trunk/sources/HeuristicLab.Collections/3.3/IObservableDictionary.cs

    r2618 r2620  
    2424using System.Linq;
    2525using System.Text;
     26using System.ComponentModel;
    2627
    2728namespace HeuristicLab.Collections {
    28   public interface IObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue> {
     29  public interface IObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, INotifyPropertyChanged {
    2930    event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsAdded;
    3031    event CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>> ItemsRemoved;
  • trunk/sources/HeuristicLab.Collections/3.3/IObservableKeyedCollection.cs

    r2618 r2620  
    2424using System.Linq;
    2525using System.Text;
     26using System.ComponentModel;
    2627
    2728namespace HeuristicLab.Collections {
    28   public interface IObservableKeyedCollection<TKey, TItem> : ICollection<TItem> {
     29  public interface IObservableKeyedCollection<TKey, TItem> : ICollection<TItem>, INotifyPropertyChanged {
    2930    TItem this[TKey key] { get; }
    3031
  • trunk/sources/HeuristicLab.Collections/3.3/IObservableList.cs

    r2618 r2620  
    2424using System.Linq;
    2525using System.Text;
     26using System.ComponentModel;
    2627
    2728namespace HeuristicLab.Collections {
    28   public interface IObservableList<T> : IList<T> {
     29  public interface IObservableList<T> : IList<T>, INotifyPropertyChanged {
    2930    event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsAdded;
    3031    event CollectionItemsChangedEventHandler<IndexedItem<T>> ItemsRemoved;
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableCollection.cs

    r2618 r2620  
    2424using System.Collections.Generic;
    2525using System.Collections.ObjectModel;
     26using System.ComponentModel;
    2627using System.Linq;
    2728using System.Text;
     
    3738    public int Capacity {
    3839      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      }
    4046    }
    4147    public int Count {
     
    8288    #region Manipulation
    8389    public void Add(T item) {
     90      int capacity = list.Capacity;
    8491      list.Add(item);
     92      if (list.Capacity != capacity)
     93        OnPropertyChanged("Capacity");
     94      OnPropertyChanged("Count");
    8595      OnItemsAdded(new T[] { item });
    8696    }
    8797    public void AddRange(IEnumerable<T> collection) {
     98      int capacity = list.Capacity;
     99      int count = list.Count;
    88100      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      }
    90107    }
    91108
    92109    public bool Remove(T item) {
    93110      if (list.Remove(item)) {
     111        OnPropertyChanged("Count");
    94112        OnItemsRemoved(new T[] { item });
    95113        return true;
     
    104122          items.Add(item);
    105123      }
    106       if (items.Count > 0)
     124      if (items.Count > 0) {
     125        OnPropertyChanged("Count");
    107126        OnItemsRemoved(items);
     127      }
    108128    }
    109129    public int RemoveAll(Predicate<T> match) {
    110130      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      }
    113137      return result;
    114138    }
    115139
    116140    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      }
    120147    }
    121148    #endregion
     
    156183    #region Helpers
    157184    public void TrimExcess() {
     185      int capacity = list.Capacity;
    158186      list.TrimExcess();
     187      if (list.Capacity != capacity)
     188        OnPropertyChanged("Capacity");
    159189    }
    160190    #endregion
     
    181211        CollectionReset(this, new CollectionItemsChangedEventArgs<T>(items, oldItems));
    182212    }
     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    }
    183220    #endregion
    184221  }
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableDictionary.cs

    r2618 r2620  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.ComponentModel;
    2526using System.Linq;
    2627using System.Text;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using System.Runtime.Serialization;
    2929
    3030namespace HeuristicLab.Collections {
     
    110110    public void Add(TKey key, TValue value) {
    111111      dict.Add(key, value);
     112      OnPropertyChanged("Item[]");
     113      OnPropertyChanged("Keys");
     114      OnPropertyChanged("Values");
     115      OnPropertyChanged("Count");
    112116      OnItemsAdded(new KeyValuePair<TKey, TValue>[] { new KeyValuePair<TKey, TValue>(key, value) });
    113117    }
    114118    void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item) {
    115119      ((ICollection<KeyValuePair<TKey, TValue>>)dict).Add(item);
     120      OnPropertyChanged("Item[]");
     121      OnPropertyChanged("Keys");
     122      OnPropertyChanged("Values");
     123      OnPropertyChanged("Count");
    116124      OnItemsAdded(new KeyValuePair<TKey, TValue>[] { item });
    117125    }
     
    121129      if (dict.TryGetValue(key, out value)) {
    122130        dict.Remove(key);
     131        OnPropertyChanged("Item[]");
     132        OnPropertyChanged("Keys");
     133        OnPropertyChanged("Values");
     134        OnPropertyChanged("Count");
    123135        OnItemsRemoved(new KeyValuePair<TKey, TValue>[] { new KeyValuePair<TKey, TValue>(key, value) });
    124136        return true;
     
    128140    bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item) {
    129141      if (((ICollection<KeyValuePair<TKey, TValue>>)dict).Remove(item)) {
     142        OnPropertyChanged("Item[]");
     143        OnPropertyChanged("Keys");
     144        OnPropertyChanged("Values");
     145        OnPropertyChanged("Count");
    130146        OnItemsRemoved(new KeyValuePair<TKey, TValue>[] { item });
    131147        return true;
     
    135151
    136152    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      }
    140162    }
    141163    #endregion
     
    190212        CollectionReset(this, new CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>>(items, oldItems));
    191213    }
     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    }
    192221    #endregion
    193222  }
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableKeyedCollectionBase.cs

    r2618 r2620  
    2424using System.Collections.Generic;
    2525using System.Collections.ObjectModel;
     26using System.ComponentModel;
    2627using System.Linq;
    2728using System.Text;
     
    9394        }
    9495      }
    95       if (!oldKeyFound) throw new ArgumentException("item not found");
     96      if (!oldKeyFound) throw new ArgumentException("Item not found");
    9697      dict.Remove(oldKey);
    9798      dict.Add(GetKeyForItem(item), item);
     99      OnPropertyChanged("Item[]");
    98100      OnItemsReplaced(new TItem[] { item }, new TItem[] { item });
    99101    }
     
    139141    public void Add(TItem item) {
    140142      dict.Add(GetKeyForItem(item), item);
     143      OnPropertyChanged("Item[]");
     144      OnPropertyChanged("Count");
    141145      OnItemsAdded(new TItem[] { item });
    142146    }
    143147    public void AddRange(IEnumerable<TItem> collection) {
    144148      if (collection == null) throw new ArgumentNullException();
    145       foreach (TItem item in collection)
     149      bool empty = true;
     150      foreach (TItem item in collection) {
    146151        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      }
    148159    }
    149160
     
    152163      if (TryGetValue(key, out item)) {
    153164        dict.Remove(key);
     165        OnPropertyChanged("Item[]");
     166        OnPropertyChanged("Count");
    154167        OnItemsRemoved(new TItem[] { item });
    155168        return true;
     
    159172    public bool Remove(TItem item) {
    160173      if (dict.Remove(GetKeyForItem(item))) {
     174        OnPropertyChanged("Item[]");
     175        OnPropertyChanged("Count");
    161176        OnItemsRemoved(new TItem[] { item });
    162177        return true;
     
    171186          items.Add(item);
    172187      }
    173       if (items.Count > 0)
     188      if (items.Count > 0) {
     189        OnPropertyChanged("Item[]");
     190        OnPropertyChanged("Count");
    174191        OnItemsRemoved(items);
     192      }
    175193    }
    176194    public int RemoveAll(Predicate<TItem> match) {
     
    181199
    182200    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      }
    186208    }
    187209    #endregion
     
    257279        CollectionReset(this, new CollectionItemsChangedEventArgs<TItem>(items, oldItems));
    258280    }
     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    }
    259288    #endregion
    260289  }
  • trunk/sources/HeuristicLab.Collections/3.3/ObservableList.cs

    r2618 r2620  
    2424using System.Collections.Generic;
    2525using System.Collections.ObjectModel;
     26using System.ComponentModel;
    2627using System.Linq;
    2728using System.Text;
     
    3738    public int Capacity {
    3839      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      }
    4046    }
    4147    public int Count {
     
    5258      set {
    5359        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        }
    5665      }
    5766    }
     
    147156    #region Manipulation
    148157    public void Add(T item) {
     158      int capacity = list.Capacity;
    149159      list.Add(item);
     160      if (list.Capacity != capacity)
     161        OnPropertyChanged("Capacity");
     162      OnPropertyChanged("Item[]");
     163      OnPropertyChanged("Count");
    150164      OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(list.Count - 1, item) });
    151165    }
    152166    public void AddRange(IEnumerable<T> collection) {
     167      int capacity = list.Capacity;
    153168      int index = list.Count;
    154169      list.AddRange(collection);
     
    158173        index++;
    159174      }
    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      }
    161182    }
    162183
    163184    public void Insert(int index, T item) {
     185      int capacity = list.Capacity;
    164186      list.Insert(index, item);
     187      if (list.Capacity != capacity)
     188        OnPropertyChanged("Capacity");
     189      OnPropertyChanged("Item[]");
     190      OnPropertyChanged("Count");
    165191      OnItemsAdded(new IndexedItem<T>[] { new IndexedItem<T>(index, item) });
    166192    }
    167193    public void InsertRange(int index, IEnumerable<T> collection) {
     194      int capacity = list.Capacity;
    168195      list.InsertRange(index, collection);
    169196      List<IndexedItem<T>> items = new List<IndexedItem<T>>();
     
    172199        index++;
    173200      }
    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      }
    175208    }
    176209
     
    179212      if (index != -1) {
    180213        list.RemoveAt(index);
     214        OnPropertyChanged("Item[]");
     215        OnPropertyChanged("Count");
    181216        OnItemsRemoved(new IndexedItem<T>[] { new IndexedItem<T>(index, item) });
    182217        return true;
     
    191226          items.Add(new IndexedItem<T>(i, list[i]));
    192227      }
    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      }
    195235      return result;
    196236    }
     
    198238      T item = list[index];
    199239      list.RemoveAt(index);
     240      OnPropertyChanged("Item[]");
     241      OnPropertyChanged("Count");
    200242      OnItemsRemoved(new IndexedItem<T>[] { new IndexedItem<T>(index, item) });
    201243    }
    202244    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      }
    206252    }
    207253
    208254    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      }
    212262    }
    213263
    214264    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      }
    218271    }
    219272    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      }
    223279    }
    224280
    225281    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      }
    229288    }
    230289    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      }
    234296    }
    235297    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      }
    239304    }
    240305    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      }
    244312    }
    245313    #endregion
     
    283351    #region Helpers
    284352    public void TrimExcess() {
     353      int capacity = list.Capacity;
    285354      list.TrimExcess();
     355      if (list.Capacity != capacity)
     356        OnPropertyChanged("Capacity");
    286357    }
    287358    #endregion
     
    321392      if (CollectionReset != null)
    322393        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));
    323401    }
    324402    #endregion
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableCollection.cs

    r2618 r2620  
    2424using System.Collections.Generic;
    2525using System.Collections.ObjectModel;
     26using System.ComponentModel;
    2627using System.Linq;
    2728using System.Text;
     
    5051      collection.ItemsRemoved += new CollectionItemsChangedEventHandler<T>(collection_ItemsRemoved);
    5152      collection.CollectionReset += new CollectionItemsChangedEventHandler<T>(collection_CollectionReset);
     53      collection.PropertyChanged += new PropertyChangedEventHandler(collection_PropertyChanged);
    5254    }
    5355    #endregion
     
    110112    }
    111113
     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
    112121    private void collection_ItemsAdded(object sender, CollectionItemsChangedEventArgs<T> e) {
    113122      OnItemsAdded(e.Items);
     
    119128      OnCollectionReset(e.Items, e.OldItems);
    120129    }
     130    private void collection_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     131      if (e.PropertyName.Equals("Count"))
     132        OnPropertyChanged(e.PropertyName);
     133    }
    121134    #endregion
    122135  }
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableDictionary.cs

    r2618 r2620  
    2323using System.Collections;
    2424using System.Collections.Generic;
     25using System.ComponentModel;
    2526using System.Linq;
    2627using System.Text;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using System.Runtime.Serialization;
    2929
    3030namespace HeuristicLab.Collections {
     
    6565      dict.ItemsReplaced += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_ItemsReplaced);
    6666      dict.CollectionReset += new CollectionItemsChangedEventHandler<KeyValuePair<TKey, TValue>>(dict_CollectionReset);
     67      dict.PropertyChanged += new PropertyChangedEventHandler(dict_PropertyChanged);
    6768    }
    6869    #endregion
     
    145146    }
    146147
     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
    147155    private void dict_ItemsAdded(object sender, CollectionItemsChangedEventArgs<KeyValuePair<TKey, TValue>> e) {
    148156      OnItemsAdded(e.Items);
     
    157165      OnCollectionReset(e.Items, e.OldItems);
    158166    }
     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    }
    159171    #endregion
    160172  }
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableKeyedCollection.cs

    r2618 r2620  
    2424using System.Collections.Generic;
    2525using System.Collections.ObjectModel;
     26using System.ComponentModel;
    2627using System.Linq;
    2728using System.Text;
     
    5758      collection.ItemsReplaced += new CollectionItemsChangedEventHandler<TItem>(collection_ItemsReplaced);
    5859      collection.CollectionReset += new CollectionItemsChangedEventHandler<TItem>(collection_CollectionReset);
     60      collection.PropertyChanged += new PropertyChangedEventHandler(collection_PropertyChanged);
    5961    }
    6062    #endregion
     
    131133    }
    132134
     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
    133142    private void collection_ItemsAdded(object sender, CollectionItemsChangedEventArgs<TItem> e) {
    134143      OnItemsAdded(e.Items);
     
    143152      OnCollectionReset(e.Items, e.OldItems);
    144153    }
     154    private void collection_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     155      if (e.PropertyName.Equals("Item[]") || e.PropertyName.Equals("Count"))
     156        OnPropertyChanged(e.PropertyName);
     157    }
    145158    #endregion
    146159  }
  • trunk/sources/HeuristicLab.Collections/3.3/ReadOnlyObservableList.cs

    r2618 r2620  
    2424using System.Collections.Generic;
    2525using System.Collections.ObjectModel;
     26using System.ComponentModel;
    2627using System.Linq;
    2728using System.Text;
     
    6061      list.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_ItemsMoved);
    6162      list.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(list_CollectionReset);
     63      list.PropertyChanged += new PropertyChangedEventHandler(list_PropertyChanged);
    6264    }
    6365    #endregion
     
    145147    }
    146148
     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
    147156    private void list_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {
    148157      OnItemsAdded(e.Items);
     
    160169      OnCollectionReset(e.Items, e.OldItems);
    161170    }
     171    private void list_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     172      if (e.PropertyName.Equals("Item[]") || e.PropertyName.Equals("Count"))
     173        OnPropertyChanged(e.PropertyName);
     174    }
    162175    #endregion
    163176  }
Note: See TracChangeset for help on using the changeset viewer.