title: WPF Simple Binding to INotifyPropertyChanged Object
body: <p>I've created the simplest binding. A textbox bound to an object in the code behind. </p>
  
  <p>Event though - the textbox remains empty.</p>
  
  <p>The window's DataContext is set, and the binding path is present.  </p>
  
  <p>Can you say what's wrong?</p>
  
  <p>XAML </p>
  
  <pre><code>&lt;Window x:Class="Anecdotes.SimpleBinding"
          x:Name="MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="SimpleBinding" Height="300" Width="300" DataContext="MainWindow"&gt;
      &lt;Grid&gt;
          &lt;TextBox Text="{Binding Path=BookName, ElementName=TheBook}" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Code behind</p>
  
  <pre><code>   public partial class SimpleBinding : Window
      {
          public Book TheBook;
  
          public SimpleBinding()
          {
              TheBook = new Book() { BookName = "The Mythical Man Month" };
              InitializeComponent();
          }
      }
  </code></pre>
  
  <p>The book object</p>
  
  <pre><code>public class Book : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged;
  
      protected void OnPropertyChanged(string name)
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(name));
          }
  
      }
  
      private string bookName;
  
      public string BookName
      {
          get { return bookName; }
          set
          {
              if (bookName != value)
              {
                  bookName = value;
                  OnPropertyChanged("BookName");
              }
          }
      }
  }
  </code></pre>