有没有办法在ObservableCollection中添加新项目或更新现有项目时获取通知或事件。说如何在ObservableCollection对象中获取更改通知
class Notify:INotifyPropertyChanged
{
private string userID { get; set; }
public string UserID
{
get { return userID; }
set
{
if (userID != value)
{
userID = value;
OnPropertyChanged("UserID");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
class MainClass
{
ObservableCollection<Notify> notifyme = new ObservableCollection<Notify>();
changed()
{
//logic where there is an update
}
}
当我称()改变