Я полагаю, что приведенный ниже код служит примером того, как решить вашу проблему. В этом примере MyCollection является свойством объектов ViewModel. ViewModel реализует интерфейс INotifyPropertyChanged.
private void AddCollectionListener()
{
if (MyCollection != null)
{
MyCollection.CollectionChanged +=
new System.Collections.Specialized.NotifyCollectionChangedEventHandler(MyCollection_CollectionChanged);
}
}
void MyCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
// Remove Listeners to each item that has been removed
foreach (object oldItem in e.OldItems)
{
ViewModel viewModel = oldItem as ViewModel;
if (viewModel != null)
{
viewModel.PropertyChanged -= viewModel_PropertyChanged;
}
}
// Add Listeners to each item that has been added
foreach (object newItem in e.NewItems)
{
ViewModel viewModel = newItem as ViewModel;
if (viewModel != null)
{
viewModel.PropertyChanged += new PropertyChangedEventHandler(viewModel_PropertyChanged);
}
}
}
void viewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
// TODO: Property Changed Logic
switch (e.PropertyName)
{
case "MyPropertyName":
// TODO: Perform logic necessary when MyPropertyName changes
break;
default:
// TODO: Perform logic for all other property changes.
break;
}
}