Class ObservableDictionary<TKey, TValue>
- Namespace
- Lers
- Assembly
- Lers.System.dll
Provides a dictionary for use with data binding.
public class ObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged
Type Parameters
TKey
Specifies the type of the keys in this collection.
TValue
Specifies the type of the values in this collection.
- Inheritance
-
ObservableDictionary<TKey, TValue>
- Implements
-
IDictionary<TKey, TValue>ICollection<KeyValuePair<TKey, TValue>>IEnumerable<KeyValuePair<TKey, TValue>>
- Inherited Members
- Extension Methods
Constructors
ObservableDictionary()
Initializes an instance of the class.
public ObservableDictionary()
ObservableDictionary(IDictionary<TKey, TValue>)
Initializes an instance of the class using another dictionary as the key/value store.
public ObservableDictionary(IDictionary<TKey, TValue> dictionary)
Parameters
dictionary
IDictionary<TKey, TValue>
Properties
this[TKey]
Gets or sets the element with the specified key.
public TValue this[TKey key] { get; set; }
Parameters
key
TKeyThe key.
Property Value
- TValue
Keys
Gets an ICollection<T> containing the keys of the IDictionary<TKey, TValue>.
public ICollection<TKey> Keys { get; }
Property Value
- ICollection<TKey>
An ICollection<T> containing the keys of the object that implements IDictionary<TKey, TValue>.
Values
Gets an ICollection<T> containing the values in the IDictionary<TKey, TValue>.
public ICollection<TValue> Values { get; }
Property Value
- ICollection<TValue>
An ICollection<T> containing the values in the object that implements IDictionary<TKey, TValue>.
Methods
Add(TKey, TValue)
Adds an element with the provided key and value to the IDictionary<TKey, TValue>.
public void Add(TKey key, TValue value)
Parameters
key
TKeyThe object to use as the key of the element to add.
value
TValueThe object to use as the value of the element to add.
Clear()
Removes all items from the IDictionary<TKey, TValue>.
public void Clear()
ContainsKey(TKey)
Determines whether the IDictionary<TKey, TValue> contains an element with the specified key.
public bool ContainsKey(TKey key)
Parameters
key
TKeyThe key to locate in the IDictionary<TKey, TValue>.
Returns
- bool
true if the IDictionary<TKey, TValue> contains an element with the key; otherwise, false.
RaisePropertyChanged(PropertyChangedEventArgs)
Allows derived classes to raise custom property changed events.
protected void RaisePropertyChanged(PropertyChangedEventArgs args)
Parameters
Remove(TKey)
Removes the element with the specified key from the IDictionary<TKey, TValue>.
public bool Remove(TKey key)
Parameters
key
TKeyThe key of the element to remove.
Returns
- bool
true if the element is successfully removed; otherwise, false. This method also returns false if
key
was not found in the original IDictionary<TKey, TValue>.
TryGetValue(TKey, out TValue)
Gets the value associated with the specified key.
public bool TryGetValue(TKey key, out TValue value)
Parameters
key
TKeyThe key whose value to get.
value
TValueWhen this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the
value
parameter. This parameter is passed uninitialized.
Returns
- bool
true if the object that implements IDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.
Events
CollectionChanged
Event raised when the collection changes.
public event NotifyCollectionChangedEventHandler CollectionChanged
Event Type
PropertyChanged
Event raised when a property on the collection changes.
public event PropertyChangedEventHandler PropertyChanged