0

I have a simple class. I can change it's properties and get notified. but the object instance property changed does not change when I change any of it's properties. How can I change the object instance property changed to enable the below event to be raised?

public class A : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public int _id;
    public int Id
    {
        get { return _id; }
        set
        {
            if (_id == value)
            {
                return;
            }

            _id = value;
            OnPropertyChanged("Id"); 
        }
    }

    public string _name;
    public string Name
    {
        get { return _name; }
        set
        {
            if (_name == value)
            {
                return;
            }

            _name = value; 
            OnPropertyChanged("Name"); 
        }
    }
}



foreach (INotifyPropertyChanged item in new ObservableCollection<A>() )
         item.PropertyChanged += new PropertyChangedEventHandler(Item_PropertyChanged);

    private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {

    }
Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
sayed saad
  • 672
  • 7
  • 12
  • I don't know exactly what you mean with "the object instance property changed does not change when I change any of it's properties". Can you tell a little bit more about your goal? The public event PropertyChangedEventHandler PropertyChanged is the event which you raise in your OnPropertyChanged("propertyName") method. – csteinmueller May 02 '12 at 15:57
  • I have a collection of object A. My collection has notify collection changed event handler. when any collection item property changed it will raise an event. The problem is when I change my item(A) properties(ID or Name) it does not change my Item (A) PropertyChanged so my event is not raised. – sayed saad May 02 '12 at 16:09

1 Answers1

0

ObservableCollection not noticing when Item in it changes (even with INotifyPropertyChanged)

This question gives a possible solution in answer 2 by simon. He inherits from ObservableCollection and hooks the collections eventshandler to every single items PropertyChanged event.

Community
  • 1
  • 1
csteinmueller
  • 2,427
  • 1
  • 21
  • 32