title: Problem with WPF Data Binding Defined in Code Not Updating UI Elements
body: <p>I need to define new UI Elements as well as data binding in code because they will be implemented after run-time. Here is a simplified version of what I am trying to do.</p>
  
  <p>Data Model:</p>
  
  <pre><code>public class AddressBook : INotifyPropertyChanged
  {
      private int _houseNumber;
      public int HouseNumber
      {
          get { return _houseNumber; }
          set { _houseNumber = value; NotifyPropertyChanged("HouseNumber"); }
      }
  
      public event PropertyChangedEventHandler PropertyChanged;
  
      protected void NotifyPropertyChanged(string sProp)
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(sProp));
          }
      }
  }
  </code></pre>
  
  <p>Binding in Code:</p>
  
  <pre><code>AddressBook book = new AddressBook();
  book.HouseNumber = 123;
  TextBlock tb = new TextBlock();
  Binding bind = new Binding("HouseNumber");
  bind.Source = book;
  bind.Mode = BindingMode.OneWay;
  tb.SetBinding(TextBlock.TextProperty, bind); // Text block displays "123"
  myGrid.Children.Add(tb);
  book.HouseNumber = 456; // Text block displays "123" but PropertyChanged event fires
  </code></pre>
  
  <p>When the data is first bound, the text block is updated with the correct house number.  Then, if I change the house number in code later, the book's PropertyChanged event fires, but the text block is not updated. Can anyone tell me why?</p>
  
  <p>Thanks,
  Ben</p>