title: TwoWay Binding a Class that implements INotifyPropertyChanged, nothing happens
body: <p>I have followed a couple of examples on the Microsoft website, the first involving ItemsSource:</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemssource%28v=VS.85%29.aspx" rel="nofollow">ItemsControl.ItemsSource Property</a>
  the second:</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/ms743695%28v=vs.100%29.aspx" rel="nofollow">How to: Implement Property Change Notification</a></p>
  
  <p>Merging togheter the two examples I have arrived to my example:</p>
  
  <p><strong>XAML</strong></p>
  
  <pre><code>&lt;Window x:Class="WpfSchede.Test.ItemsSourceTest"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:c="clr-namespace:WpfSchede.Test"
      Title="ItemsSourceTest" Height="352" Width="467"&gt;
  &lt;Window.Resources&gt;
      &lt;c:NameList x:Key="NameListData"&gt;&lt;/c:NameList&gt;
      &lt;DataTemplate x:Key="NameItemTemplate"&gt;
          &lt;TextBlock Width="200" Text="{Binding Path=FullName, Mode=TwoWay}" /&gt;
      &lt;/DataTemplate&gt;
  &lt;/Window.Resources&gt;                   
  &lt;Grid&gt;
      &lt;ListBox ItemsSource="{Binding Source={StaticResource NameListData}}" ItemTemplate="{StaticResource NameItemTemplate}" Margin="12,12,120,65" Name="listBoxNames" IsSynchronizedWithCurrentItem="True"&gt; 
      &lt;/ListBox&gt;
      &lt;Button Content="Change First Name" Height="23" HorizontalAlignment="Left" Margin="12,270,0,0" Name="buttonChangeName" VerticalAlignment="Top" Width="163" Click="buttonChangeName_Click" /&gt;
      &lt;Button Content="Change Full Name" Height="23" HorizontalAlignment="Left" Margin="193,270,0,0" Name="buttonChangeFullName" VerticalAlignment="Top" Width="163" Click="buttonChangeFullName_Click" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>XAML.CS</strong></p>
  
  <pre><code>using System.Windows;
  namespace WpfSchede.Test
  {
  public partial class ItemsSourceTest : Window
  {
      public ItemsSourceTest()
      {
          InitializeComponent();
      }
  
      private void buttonChangeName_Click(object sender, RoutedEventArgs e)
      {
          PersonName p = listBoxNames.SelectedItem as PersonName;
          p.FirstName = "Andrew";
      }
  
      private void buttonChangeFullName_Click(object sender, RoutedEventArgs e)
      {
          PersonName p = listBoxNames.SelectedItem as PersonName;
          p.FullName = "Andrea Rossi";
      }
    }
  }
  </code></pre>
  
  <p><strong>NameList Class</strong></p>
  
  <pre><code>using System.Collections.ObjectModel;
  using System.ComponentModel;
  
  namespace WpfSchede.Test
  {
  public class NameList : ObservableCollection&lt;PersonName&gt;
  {
      public NameList()
          : base()
      {
          Add(new PersonName("Wil", "Cath"));
          Add(new PersonName("Isak", "Dinesen"));
          Add(new PersonName("Victor", "Hugo"));
          Add(new PersonName("Jules", "Verne"));
          Add(new PersonName("Leonardo", "Rossi"));
      }
  }
  
  public class PersonName : INotifyPropertyChanged 
  {
      private string firstName;
      private string lastName;
      // Define the event
      public event PropertyChangedEventHandler PropertyChanged; 
  
      public PersonName(string first, string last)
      {
          this.firstName = first;
          this.lastName = last;
      }
  
      public string FirstName
      {
          get { return firstName; }
          set { 
              firstName = value; 
              OnPropertyChanged(value);
          }
      }
  
      public string LastName
      {
          get { return lastName; }
          set { lastName = value; }
      }
  
      public string FullName
      {
          set {
              string full = value as string;
              char[] sep = { ' ' };
              string[] n = full.Split(sep);
              this.FirstName = n[0];
              this.LastName = n[1];
              OnPropertyChanged(value);
          }
          get { return firstName + " " + lastName; }
      }
  
      protected void OnPropertyChanged(string name)
      {
          PropertyChangedEventHandler handler = PropertyChanged;
          if (handler != null)
          {
              handler(this, new PropertyChangedEventArgs(name));
          }
  
      }
   }
  }
  </code></pre>
  
  <p>I have two questions.</p>
  
  <p>First) When clicking one of the Buttons I was expecting the ListBox to reflect the changes, instead nothing happens! What am I missing?</p>
  
  <p>Second) In the DataTemplate I bind to the FullName (binding to only the FirstName would have been easier for the example sake, but seems to me like too a simplification). So I have chosed to bind to a Property FullName, for which I have written my custom code in NameList class and the DataTemplate code. What is wrong with my code? Is right to specify Mode=TwoWay in DataTemplate?</p>