AsyncObservableDictionary - Aghyad-Khlefawi/Coddee GitHub Wiki
This collection extends the functionality of the AsyncObservableCollection by adding a dictionary behavior to the collection.
| Name | Description |
|---|---|
| TKey | The dictionary key type |
| TValue | The collection value type, this type must implements the IUniqueObject because the GeyKey property will be automatically used as the key for each item in the dictionary |
| Name | Description |
|---|---|
| FillDicionaryValues | Copy the content of another collection |
| Name | Description |
|---|---|
| Item[TKey] | Gets the element with the specified key |
The best way to create an instance of this collection is to use the factory method AsyncObservableDictionary.Create() which will create the collection on the UI thread.
C# Example:
//Set the owning thread in start of the application
UISynchronizationContext.SetContext(SynchronizationContext.Current);
//Create the dictionary
var dictionary = AsyncObservableDictionary<int,Person>.Create();
//Subscribe to the SelectedItemChanged event
dictionary.SelectedItemChanged += (sender, item) =>
{
MessageBox.Show($"An item was selected {item.FirstName}");
};
var person = new Person { ID = 1,FirstName = "Aghyad" };
//Add an item to the collection
dictionary.Add(person);
//Set the selected item (This will trigger the SelectedItemChanged event)
dictionary.SelectedItem = person;
//Add more items to the collection in this case using a method (GetFromDatabase) which returns Task<IEnumerable<Person>>
await dictionary.FillAsync(GetFromDatabase());
//Get the item by the ID properties
var samePesron = dictionary[1];