title: Two Way Data Binding With a Dictionary in WPF
body: <p>I'd like to bind a <code>Dictionary&lt;string, int&gt;</code> to a <code>ListView</code> in WPF. I'd like to do this in such a way that the <code>Values</code> in the <code>Dictionary</code> get updated via the data binding mechanism. I don't want to change the <code>Keys</code> just the <code>Values</code>. I also don't care about adding new mappings to the <code>Dictionary</code>. I just want to update existing ones.</p>
  
  <p>Setting the Dictionary as the <code>ItemsSource</code> of the <code>ListView</code> doesn't accomplish this.  It doesn't work because the <code>ListView</code> uses the Enumerator to access the contents of the <code>Dictionary</code> and the elements of that enumeration are immutable <code>KeyValuePair</code> objects.</p>
  
  <p>My current line of investigation attempts to use the <code>Keys</code> property. I assign this to the <code>ItemsSource</code> property of my <code>ListView</code>. This does allow me to display the <code>Keys</code> but I don't know enough about WPF's databinding mechanism to access the <code>Values</code> in the <code>Dictionary</code>.</p>
  
  <p>I found this question: <a href="https://stackoverflow.com/questions/666856/access-codebehind-variable-in-xaml">Access codebehind variable in XAML</a> but still can't seem to bridge the gap.</p>
  
  <p>Do any of you know how to make this approach work?
  Does anyone have a better approach?</p>
  
  <p>It seems like, as a last resort, I could build a custom object and stick it in a <code>List</code> from which I recreate/update my <code>Dictionary</code> but this seems like a way to circumvent the built-in data binding functionality rather than effectively utilize it.</p>