title: How to set a binding in Code?
body: <p>I have the need to set a binding in code.</p>
  
  <p>I can't seem to get it right tho.</p>
  
  <p>This is what i have tried:</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;TextBox Name="txtText"&gt;&lt;/TextBox&gt;
  </code></pre>
  
  <p>Code behind:</p>
  
  <pre><code>Binding myBinding = new Binding("SomeString");
  myBinding.Source = ViewModel.SomeString;
  myBinding.Mode = BindingMode.TwoWay;
  myBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
  BindingOperations.SetBinding(txtText, TextBox.TextProperty, myBinding);
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>public string SomeString
      {
        get
        { 
            return someString;
        }
        set 
        { 
            someString= value;
            OnPropertyChanged("SomeString");
        }
      }
  </code></pre>
  
  <p>The property is not updating when i set it. </p>
  
  <p>What am i doing wrong?</p>