title: Notify ObservableCollection when Item changes
body: <p>I found on this link </p>
  
  <p><a href="https://stackoverflow.com/questions/1427471/c-observablecollection-not-noticing-when-item-in-it-changes-even-with-inotify">ObservableCollection not noticing when Item in it changes (even with INotifyPropertyChanged)</a></p>
  
  <p>some techniques to notify a Observablecollection that an item has changed. the TrulyObservableCollection in this link seems to be what i'm looking for.</p>
  
  <pre><code>public class TrulyObservableCollection&lt;T&gt; : ObservableCollection&lt;T&gt;
  where T : INotifyPropertyChanged
  {
      public TrulyObservableCollection()
      : base()
      {
          CollectionChanged += new NotifyCollectionChangedEventHandler(TrulyObservableCollection_CollectionChanged);
      }
  
      void TrulyObservableCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
      {
          if (e.NewItems != null)
          {
              foreach (Object item in e.NewItems)
              {
                  (item as INotifyPropertyChanged).PropertyChanged += new PropertyChangedEventHandler(item_PropertyChanged);
              }
          }
          if (e.OldItems != null)
          {
              foreach (Object item in e.OldItems)
              {
                  (item as INotifyPropertyChanged).PropertyChanged -= new PropertyChangedEventHandler(item_PropertyChanged);
              }
          }
      }
  
      void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
      {
          NotifyCollectionChangedEventArgs a = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
          OnCollectionChanged(a);
      }
  }
  </code></pre>
  
  <p>But when I try to use it, I don't get notifications on the collection. I'm not sure how to correctly implement this in my C# Code:</p>
  
  <p>XAML :</p>
  
  <pre><code>    &lt;DataGrid AutoGenerateColumns="False" ItemsSource="{Binding MyItemsSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridCheckBoxColumn Binding="{Binding MyProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  </code></pre>
  
  <p>ViewModel :</p>
  
  <pre><code>public class MyViewModel : ViewModelBase
  {
      private TrulyObservableCollection&lt;MyType&gt; myItemsSource;
      public TrulyObservableCollection&lt;MyType&gt; MyItemsSource
      {
          get { return myItemsSource; }
          set 
          { 
              myItemsSource = value; 
              // Code to trig on item change...
              RaisePropertyChangedEvent("MyItemsSource");
          }
      }
  
      public MyViewModel()
      {
          MyItemsSource = new TrulyObservableCollection&lt;MyType&gt;()
          { 
              new MyType() { MyProperty = false },
              new MyType() { MyProperty = true },
              new MyType() { MyProperty = false }
          };
      }
  }
  
  public class MyType : ViewModelBase
  {
      private bool myProperty;
      public bool MyProperty
      {
          get { return myProperty; }
          set 
          {
              myProperty = value;
              RaisePropertyChangedEvent("MyProperty");
          }
      }
  }
  
  public class ViewModelBase : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged;
  
      protected void RaisePropertyChangedEvent(string propertyName)
      {
          if (PropertyChanged != null)
          {
              PropertyChangedEventArgs e = new PropertyChangedEventArgs(propertyName);
              PropertyChanged(this, e);
          }
      }
  }
  </code></pre>
  
  <p>When i run the program, i have the 3 checkbox to false, true, false as in the property initialisation.
  but when i change the state of one of the ckeckbox, the program go through item_PropertyChanged but never in MyItemsSource Property code.</p>