Skip to content

ObservableDictionary

Mark Smith edited this page Aug 26, 2016 · 6 revisions

ObservableDictionary<TKey,TValue>

This class provides an observable IDictionary<TKey, TValue> which can be data bound with Xamarin.Forms. It acts like a regular Dictionary but provides change notifications to any data bound visual. You can provide the backing store through the constructor, or if not supplied, it creates a Dictionary<TKey,TValue>.

Methods

BeginMassUpdate : this method turns off change notification reporting to allow for multiple updates to be performed on the dictionary. The return type is an IDisposable which, when disposed, will turn updates back on.

Example

<Label Text="{Binding Path=[Counter], StringFormat='{0}'}" />

The corresponding binding context would be:

var dictionary = new ObservableDictionary<string, object> { { "Counter", 10 } };
BindingContext = dictionary;
...
dictionary["Counter"] = 11; // UI would be updated.

Clone this wiki locally