title: Data binding in code-behind
body: <p>I want to setup a binding between a class instance and two WPF textboxes. Still, the textboxes don't change their status and I can't figure out what I'm doing wrong.</p>
  
  <p>XAML</p>
  
  <pre><code>&lt;DockPanel&gt;
     &lt;TextBlock Style="{StaticResource caption}"&gt;Testing System&lt;/TextBlock&gt;
     &lt;TextBlock DockPanel.Dock="Left" x:Name="txt1" Text="DC"/&gt;
     &lt;TextBlock DockPanel.Dock="Right" x:Name="txt2"  Text="PD"/&gt;
     &lt;Button Height="20" Width="100" Click="clickBinding"&gt;Bind&lt;/Button&gt;
     &lt;Button Height="20" Width="100" Click="clickChangeBinding"&gt;Change Status&lt;/Button&gt;
  &lt;/DockPanel&gt;
  </code></pre>
  
  <p>MainWindow.xaml.cs</p>
  
  <pre><code>private ADSbinding myADS = new ADSbinding();
  private void clickBinding(object sender, RoutedEventArgs e)
  {
     Binding b1, b2;
  
     b1 = new Binding();
     b2 = new Binding();
     b1.Source = myADS.DeviceConfigured;
     b2.Source = myADS.ProcessingData;
  
  
     b1.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
     b2.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
  
     BindingOperations.SetBinding(txt1, TextBlock.TextProperty, b1);
     BindingOperations.SetBinding(txt2, TextBlock.TextProperty, b2); 
     }
  
     private void clickChangeBinding(object sender, RoutedEventArgs e)
     {
        myADS.changedata();
     }
  </code></pre>
  
  <p>Class:</p>
  
  <pre><code>public class ADSbinding : INotifyPropertyChanged
  {
     public event PropertyChangedEventHandler PropertyChanged;
  
     private string deviceConfigured = "false";
     private string processingData = "false";
  
     public ADSbinding()
     {
        ProcessingData = "true";
     }
  
     // Get-Set methods
     public string DeviceConfigured
     {
        get { return deviceConfigured; }
        set 
        { 
           deviceConfigured = value;
           Changed("DeviceConfigured");
        }
     }
     public string ProcessingData
     {
        get { return processingData; }
        set
        {
           processingData = value;
           Changed("ProcessingData");
        }
     }
  
     private void Changed(string propertyName)
     {
        if (PropertyChanged != null)
           PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     }
  
     public void changedata()
     {
        DeviceConfigured = "change";
        ProcessingData = "change";
      }
  }
  </code></pre>
  
  <p>When pressing "clickBinding" the status changes, when "clickChangeBinding" it remains, by clicking "clickBinding" again it changes. Its a very straight forward attempt and I can't figure out where the problem is. Anyone?</p>