Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - How can I implement an ObservableCollection<K,T> with a key (like a Dictionary)?

I have used an ObservableCollection with WPF for binding and this works well. What I really want at the moment is a Dictionary like one, that has a key that I can use, so effectively like "ObservableCollection".

Can you suggest the code that could be used to provide such an ObservableCollection? The goal is to have a Dictionary like structure that I can bind to from WPF.

Thanks

like image 956
Greg Avatar asked Sep 29 '10 02:09

Greg


2 Answers

How about:

var collection = new ObservableCollection<KeyValuePair<TKey, TValue>>();

You should be able to address it with:

collection.First(x => x.Key == *your key value*) .Key or .Value

like image 155
Hitchen Avatar answered Oct 19 '22 23:10

Hitchen


Someone already made it. I haven't try it yet but nothing to lose.

like image 6
ktutnik Avatar answered Oct 20 '22 00:10

ktutnik