Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you're looking for is something akin to an <code>ObservableCollection&lt;T&gt;</code> but for a dictionary. A bit of Googling found the following from <a href="http://www.drwpf.com/blog/Home/tabid/36/BlogDate/2007-09-30/Default.aspx" rel="nofollow noreferrer">Dr. WPF on building an <code>ObservableDictionary</code></a>:</p> <blockquote> <p><strong>Pros and Cons</strong></p> <p>The benefit to using an observable dictionary, of course, is that the dictionary can serve as the ItemsSource for a databound control and you can still access the dictionary in code the same way you access any other dictionary. It is truly an indexed dictionary of objects. There are certainly some limitations inherent in the very idea of making a dictionary observable. Dictionaries are built for speed. When you impose the behaviors of an observable collection on a dictionary so that the framework can bind to it, you add overhead.</p> <p>Also, a dictionary exposes its <code>Values</code> and <code>Keys</code> collections through separate properties of the same name. These collections are of types <code>Dictionary&lt;TKey, TValue&gt;.ValueCollection</code> and <code>Dictionary&lt;TKey, TValue&gt;.KeyCollection</code>, respectively. These CLR-defined collections are not observable. As such, you cannot bind to the Values collection or to the Keys collection directly and expect to receive dynamic collection change notifications. You must instead bind directly to the observable dictionary.</p> </blockquote> <p>Now, you may run into a problem with updating the Key, as you would then need to somehow convince the dictionary to <em>Move</em> your item. I would suggest taking Dr. WPF's <code>ObservableDictionary</code> and instead using a <a href="http://msdn.microsoft.com/en-us/library/ms132438.aspx" rel="nofollow noreferrer"><code>KeyedCollection</code></a> as the backing store. That way the Key is derived from the Item itself, and updates move the object in the <code>ObservableDictionary</code> automatically.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload