title: Two-way WPF binding to Properties of a class inside of an ObservableCollection
body: <p>I've searched as best as I can, and I can't find an answer to this specific problem that I have... WPF binding seems to be great and all, but I end up banging my head against the wall more often than not.</p>
  
  <p>Okay, I have a singleton class which is ultimately the one that I'm binding to:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Imports System.ComponentModel
  Imports System.Collections.ObjectModel
  
  Public Class AmandaSeyfried
      Implements INotifyPropertyChanged
  
      Shared _config As New config
  
      Public Event PropertyChanged(sender As Object, E As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
  
      Protected Overridable Sub OnPropertyChanged(propertyName As String)
          RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
      End Sub
  
      Private Shared _thisInstance As AmandaSeyfried
  
      Protected Sub New()
          ' initialization goes here
      End Sub
  
      Public Shared Function GetSingleton() As AmandaSeyfried
          ' initialize object if it hasn't already been done
          If _thisInstance Is Nothing Then
              _thisInstance = New AmandaSeyfried
          End If
  
          ' return the initialized instance
          Return _thisInstance
      End Function
  
      Public Class CountryTranslation
          Implements INotifyPropertyChanged
  
          Private Property _englishCountryName As String = ""
          Public Property EnglishCountryName As String
              Get
                  Return _EnglishCountryName
              End Get
              Set(value As String)
                  If _englishCountryName &lt;&gt; value Then
                      _englishCountryName = value
                      RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("EnglishCountryName"))
                  End If
              End Set
          End Property
  
          Private Property _foreignCountryName As String = ""
          Public Property ForeignCountryName As String
              Get
                  Return _foreignCountryName
              End Get
              Set(value As String)
                  If _foreignCountryName &lt;&gt; value Then
                      _foreignCountryName = value
                      RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("ForeignCountryName"))
                  End If
              End Set
          End Property
  
          Public Event PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
      End Class
  
      Private WithEvents _countryTranslations As New ObservableCollection(Of CountryTranslation)
      Public Property CountryTranslations As ObservableCollection(Of CountryTranslation)
          Get
              If _config.GetKeyTextValue("countryTranslations") &lt;&gt; "" Then
                  Dim reader As New IO.StringReader(_config.GetKeyTextValue("countryTranslations"))
                  Dim Serializer As New Xml.Serialization.XmlSerializer(_countryTranslations.GetType)
                  _countryTranslations = Serializer.Deserialize(reader)
              End If
  
              Return _countryTranslations
          End Get
          Set(value As ObservableCollection(Of CountryTranslation))
              _countryTranslations = value
              RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("CountryTranslations"))
          End Set
      End Property
  
      Private Sub CountryTranslationCollectionChanged(sender As Object, e As Specialized.NotifyCollectionChangedEventArgs) Handles _countryTranslations.CollectionChanged
          Dim newStringWriter As New IO.StringWriter
          Dim NewSerializer As New Xml.Serialization.XmlSerializer(_countryTranslations.GetType)
          NewSerializer.Serialize(newStringWriter, _countryTranslations)
          _config.SaveKeyTextValue("countryTranslations", newStringWriter.ToString)
          RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("CountryTranslations"))
      End Sub
  
  End Class
  </code></pre>
  
  <p><code>_config</code> is a misnamed helper class that stores and retrieves data from a local SqlCe instance.  Essentially the object is serialized, stored in the DB, and then pulled out of the DB any times it's needed and deserialized back into an object.  All in all, it seems to be working fairly well.</p>
  
  <p>My problem is that although I can bind to the object, and I can monitor when a row is added in a WPF DataGrid via the CollectionChangedMethod handler, I don't get any notification when either of the two properties of CountryTranslation are changed.</p>
  
  <p>The rest of my related code is... XAML... there's obviously more, but I don't believe the XAML portion of the binding is to blame, so I'll trim it to the relevant:</p>
  
  <pre class="lang-xaml prettyprint-override"><code>&lt;toolkit:DataGrid Margin="12,12,12,12" ItemsSource="{Binding Path=KarenSmith.CountryTranslations, Mode=TwoWay}" AutoGenerateColumns="False" HorizontalAlignment="Stretch" Width="Auto" SelectionMode="Single"&gt;
      &lt;toolkit:DataGrid.Columns&gt;
          &lt;toolkit:DataGridTextColumn Width="283" Binding="{Binding EnglishCountryName,Mode=TwoWay}" /&gt;
          &lt;toolkit:DataGridTextColumn Width="283" Binding="{Binding ForeignCountryName,Mode=TwoWay}" /&gt;
      &lt;/toolkit:DataGrid.Columns&gt;
  &lt;/toolkit:DataGrid&gt;
  </code></pre>
  
  <p>And the nice and simple code-behind:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Class Preferences
  
      Public Property KarenSmith As AmandaSeyfried = AmandaSeyfried.GetSingleton
  
      Sub New()
  
          ' This call is required by the designer.
          InitializeComponent()
  
          ' Add any initialization after the InitializeComponent() call.
          DataContext = Me
  
      End Sub
  
      Private Sub Close_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
          Me.Close()
      End Sub
  End Class
  </code></pre>
  
  <p>If I throw some break points on the Getter and Setters of the CountryTranslation class, I can monitor when they're being changed (via the datagrid, so binding is working), but try as I might I can't figure out how to raise an event based upon that back in the main class to subsequently update the datastore to show the changes.</p>