title: Two-way databinding for a dictionary in UWP/XAML
body: <p>I currently have an application where I'm parsing a YAML dictionary.  I have a model named <code>Line</code> that looks like this - </p>
  
  <pre><code>    public class Line
      {
  
          private ObservableDictionary&lt;string, string&gt; language = new ObservableDictionary&lt;string, string&gt;();
  
          public Line()
          {
              Language = new Dictionary&lt;string, string&gt;();
          }
  
          // used with the YAML parser
          [YamlMember(Alias = "language")]
          public Dictionary&lt;string, string&gt; Language { get; set; }
  
      }
  </code></pre>
  
  <p>You've probably noticed that I'm using an <code>ObservableDictionary</code>, which is not a standard type.  I took the code from this <a href="https://stackoverflow.com/a/14410196/2584408">other StackOverflow answer</a>.  As I understand it, it's just setting up the necessary <code>INotifyPropertyChanged</code> interface.</p>
  
  <p>Anyway, for my <code>Line</code>, I have a <code>ListView</code> populated with a dictionary of translations represented as the language abbreviation and a textbox.  To better exemplify what I'm talking about, here is a graphic.</p>
  
  <p><a href="https://i.stack.imgur.com/ICmTV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ICmTV.png" alt="enter image description here"></a></p>
  
  <p>In my <code>App.xaml</code>, I have a <code>DataTemplate</code> for my ListView defined - together, they look like this:</p>
  
  <pre><code>&lt;ListView 
      ItemTemplate="{StaticResource LinesTemplateItem}" 
      ItemsSource="{Binding Value.Language}" 
      SelectionMode="None"&gt;
  &lt;/ListView&gt;
  
  ...
  
  &lt;DataTemplate x:Key="LinesTemplateItem"&gt;
      &lt;StackPanel Background="Transparent"&gt;
          &lt;TextBlock Text="{Binding Key}" /&gt;
          &lt;TextBox Text="{Binding Value, Mode=TwoWay}" /&gt;
      &lt;/StackPanel&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>Everything seems like it should work fine.  My data shows properly.  However, when I change a value, it does not update the underlying source with the error:</p>
  
  <pre><code>Error: Cannot save value from target back to source. 
  BindingExpression: Path='Value' DataItem='Windows.Foundation.Collections.IKeyValuePair`2&lt;String,String&gt;'; 
  target element is 'Windows.UI.Xaml.Controls.TextBox' (Name='null'); 
  target property is 'Text' (type 'String').
  </code></pre>
  
  <p>From the error, I would guess that for some reason the databinding is targeting the entire UI control instead of the text inside of it.  I've been searching for a while, but I can't seem to figure out how to fix this error.  Any help is appreciated.  Thanks.</p>