title: C#: Remove Events from ObservableCollection?
body: <p>I've a ObserableCollection with Items in it, which implement the INotifyPropertyChanged Interface.
  This is how I create it:</p>
  
  <pre><code>        var myCollection = new ObservableCollection&lt;MyViewModel&gt;();
          myCollection.CollectionChanged += OnCollectionChanged;
  </code></pre>
  
  <p>_</p>
  
  <pre><code>        private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
          {
              if (e.NewItems != null)
              {
                  if (e.Action == NotifyCollectionChangedAction.Remove)
                  {
                      foreach (ViewModelBase item in e.NewItems)
                      {
                          item.PropertyChanged -= myViewModelPropertyChanged;
                      }
                  }
                  else if (e.Action == NotifyCollectionChangedAction.Add)
                  {
                      foreach (ViewModelBase item in e.NewItems)
                      {
                          item.PropertyChanged += myViewModelPropertyChanged;
                      }
                  }
              }
          }
  </code></pre>
  
  <p>Now my question is, doI need to loop trough all items and remove the "myViewModelPropertyChanged" before doing another </p>
  
  <pre><code>myCollection = new ObservableCollection&lt;MyViewModel&gt;();
  </code></pre>
  
  <p>or does this happen automatically? What about a 
      myCollection.Clear();</p>
  
  <p>Thanks for any input.</p>
  
  <p>Cheers
  Joseph</p>