Hello,
I've a ObserableCollection with Items in it, which implement the INotifyPropertyChanged Interface. This is how I create it:
var myCollection = new ObservableCollection<MyViewModel>();
myCollection.CollectionChanged += OnCollectionChanged;
_
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;
}
}
}
}
Now my question is, doI need to loop trough all items and remove the "myViewModelPropertyChanged" before doing another
myCollection = new ObservableCollection<MyViewModel>();
or does this happen automatically? What about a myCollection.Clear();
Thanks for any input.
Cheers Joseph