Click or drag to resize
ObservableDictionaryTKey, TValue Class
Inheritance Hierarchy
SystemObject
  System.Collections.GenericDictionaryTKey, TValue
    DW.SharpToolsObservableDictionaryTKey, TValue

Namespace: DW.SharpTools
Assembly: DW.SharpTools (in DW.SharpTools.dll) Version: 2.4.0.0 (2.4.0.0)
Syntax
C#
public class ObservableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, 
	INotifyCollectionChanged, INotifyPropertyChanged

Type Parameters

TKey
The type of the keys in the dictionary.
TValue
The type of the values in the dictionary.

The ObservableDictionaryTKey, TValue type exposes the following members.

Constructors
  NameDescription
Public methodObservableDictionaryTKey, TValue
Initializes a new instance of the DW.SharpTools.ObservableDictionary{TKey, TValue} class that is empty, has the default initial capacity, and uses the default equality comparer for the key type.
Public methodObservableDictionaryTKey, TValue(IDictionaryTKey, TValue)
Initializes a new instance of the DW.SharpTools.ObservableDictionary{TKey, TValue} class that contains elements copied from the specified System.Collections.Generic.IDictionary{TKey,TValue} and uses the default equality comparer for the key type.
Public methodObservableDictionaryTKey, TValue(IEqualityComparerTKey)
Initializes a new instance of the DW.SharpTools.ObservableDictionary{TKey, TValue} class that is empty, has the default initial capacity, and uses the specified System.Collections.Generic.IEqualityComparer{T}.
Public methodObservableDictionaryTKey, TValue(Int32)
Initializes a new instance of the DW.SharpTools.ObservableDictionary{TKey, TValue} class that is empty, has the specified initial capacity, and uses the default equality comparer for the key type.
Public methodObservableDictionaryTKey, TValue(IDictionaryTKey, TValue, IEqualityComparerTKey)
Initializes a new instance of the DW.SharpTools.ObservableDictionary{TKey, TValue} class that contains elements copied from the specified System.Collections.Generic.IDictionary{TKey, TValue} and uses the specified System.Collections.Generic.IEqualityComparer{T}.
Public methodObservableDictionaryTKey, TValue(Int32, IEqualityComparerTKey)
Initializes a new instance of the DW.SharpTools.ObservableDictionary{TKey, TValue} class that is empty, has the specified initial capacity, and uses the specified System.Collections.Generic.IEqualityComparer{T}.
Top
Methods
  NameDescription
Public methodAdd
Adds the specified key and value to the dictionary.
Public methodClear
Removes all keys and values from the DW.SharpTools.ObservableDictionary{TKey, TValue}.
Public methodRemove
Removes the value with the specified key from the DW.SharpTools.ObservableDictionary{TKey, TValue}.
Top
Properties
  NameDescription
Public propertyItem
Gets or sets the value associated with the specified key.
Top
Events
  NameDescription
Public eventCollectionChanged
Occurs when the collection changes.
Public eventPropertyChanged
Occurs when a property value changes.
Top
Examples
C#
public class MainViewModel
{
    public MainViewModel()
    {
        Items = new ObservableDictionary<int, string>();
    }

    public ObservableDictionary<int, string> Items { get; set; }

    private void AddItem()
    {
        var index = Items.Count + 1;
        var value = string.Format("Key: {0}; Value {1}", Items.Count, index);
        Items.Add(index, value);
    }
}
XAML
<Button Content="Add Item" Command="{Binding AddItemCommand}" />

<ListBox DataContext="{Binding Items}" ItemsSource="{Binding }" />
See Also