1
0
mirror of https://github.com/chylex/Backup-Essentials.git synced 2024-12-22 15:42:45 +01:00
Backup-Essentials/BackupEssentials/Utils/Collections/ObservableDictionary.cs

35 lines
1.1 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
namespace BackupEssentials.Utils.Collections{
class ObservableDictionary<TKey,TValue> : Dictionary<TKey,TValue>, INotifyPropertyChanged{
public event PropertyChangedEventHandler PropertyChanged;
public bool PauseObservation = false;
public new TValue this[TKey key] {
get { return base[key]; }
set { base[key] = value; OnChanged(key); }
}
public new void Add(TKey key, TValue value){
base.Add(key,value);
OnChanged(key);
}
public void Add(KeyValuePair<TKey,TValue> item){
base.Add(item.Key,item.Value);
OnChanged(item.Key);
}
public new bool Remove(TKey key){
bool val = base.Remove(key);
if (val)OnChanged(key);
return val;
}
private void OnChanged(TKey key){
if (PropertyChanged != null && !PauseObservation)PropertyChanged(this,new PropertyChangedEventArgs(key.ToString()));
}
}
}