title: Setting Binding in code to Text property on TextBox WPF not working
body: <p>I Have the following XAML in UserControl:</p>
  
  <pre><code>&lt;StackPanel Orientation="Horizontal" Name="spContainer"&gt;
      &lt;TextBlock x:Name="tbLabelBefore" MinWidth="50" Text="{Binding LabelBefore}"&gt;&lt;/TextBlock&gt;
      &lt;TextBox Name="txtKey" MinWidth="120"&gt;&lt;/TextBox&gt;
      &lt;TextBlock Name="tbValue" MinWidth="50"&gt;&lt;/TextBlock&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>Next I want to set binding dynamically to Text property on the TextBox-txtKey <strong>from proxy class</strong>.</p>
  
  <p>I Do the following:</p>
  
  <pre><code>MDLookup lok = SelectedObject as MDLookup;
  
  string bnd = "Model."+ lok.Name +".Value";            
  Binding binding = new Binding(bnd);
  binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
  //binding.ValidatesOnDataErrors = true;
  //binding.NotifyOnValidationError = true;
  binding.Mode = BindingMode.TwoWay;
  lok.TxtKey.SetBinding(TextBox.TextProperty, binding);
  </code></pre>
  
  <p>Here lok is instance of my user control. And TxtKey is Property in my UserControl of type TextBox that returns the txtKey element:</p>
  
  <pre><code>[XmlIgnore]
  [Browsable(false)]
  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  public TextBox TxtKey
  {
      get { return this.txtKey; }
      set { this.txtKey = value; }
  }
  </code></pre>
  
  <p>If I put:</p>
  
  <pre><code>lok.TxtKey.Text = "Some Text"
  </code></pre>
  
  <p>This works.
  Also this code for setting binding works in my constructor of my user control. But here doesn't. Any idea why?</p>
  
  <p>Additional: I have ovverided ShouldSerializeContent</p>
  
  <pre><code>public override bool ShouldSerializeContent()
  {
      return false;
  }
  </code></pre>
  
  <blockquote>
    <p>The point is I serialize xaml from multiple controls in databasebase and afterwards dynamically load and set DataContext.</p>
  </blockquote>