我有一个简单的课程。我可以更改它的属性并得到通知。但是当我更改它的任何属性时,更改的对象实例属性不会改变。如何更改已更改的对象实例属性以启用以下事件?
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)
{
}