title: How does WPF INotifyPropertyChanged work?
body: <p>This is a typical INotifyPropertyChanged implementation for using Binding in WPF/C#.</p>
  
  <pre><code>namespace notifications.ViewModel
  {
      class MainViewModel : INotifyPropertyChanged
      {
          public const string NamePropertyName = "CheckBoxState";
          private bool _checkboxstate = true;
  
          public bool CheckBoxState
          {
              get { return _checkboxstate; }
              set
              {
                  if (_checkboxstate == value) return;
                  _checkboxstate = value;
                  RaisePropertyChanged(NamePropertyName);
              }
          }
          public event PropertyChangedEventHandler PropertyChanged;
          private void RaisePropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
              {
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
              }
          }
      }
  }
  </code></pre>
  
  <p>I also have a XAML code that has a binding to <code>CheckBoxState</code>. <img src="https://i.stack.imgur.com/RfxAs.png" alt="enter image description here"></p>
  
  <pre><code>&lt;Grid&gt;
      &lt;StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"&gt;
          &lt;CheckBox Content="Click Me" IsChecked="{Binding Path=CheckBoxState, Mode=TwoWay}" /&gt;
          &lt;TextBlock Text="{Binding Path=CheckBoxState, Mode=TwoWay}" /&gt;
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>This is the MainWindow.xaml.cs to link between the DataContext and model.</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      notifications.ViewModel.MainViewModel model = new notifications.ViewModel.MainViewModel();
  
      public MainWindow()
      {
          InitializeComponent();
          this.DataContext = model;
      }
  }
  </code></pre>
  
  <p>When the user sets the check box, I think what would happen is as follows : <code>IsChecked</code> becomes true, and with <code>"{Binding Path=CheckBoxState, Mode=TwoWay}"</code>, <code>CheckBoxState</code> property becomes true to call <code>RaisePropertyChanged()</code> and accordingly <code>PropertyChanged()</code>. As the parameter to this function is <code>CheckBoxState</code>, every Binding with Path <code>CheckBoxState</code> is notified to update itself.  </p>
  
  <ul>
  <li>How does this call activates <code>&lt;TextBlock Text="{Binding Path=CheckBoxState, Mode=TwoWay}" /&gt;</code>? What's the C#'s magic behind this to make it possible?</li>
  <li>Why is <code>if (PropertyChanged != null)</code> necessary? Who sets up the PropertyChanged to what value? </li>
  <li>The meaning of <code>Mode=TwoWay</code> looks like that it not only can signal the change, but also updates the content when other Binding element with the same name in binding changes, then what about OneWay mode? Can we set a Binding as source only or target only? </li>
  </ul>