有沒有辦法在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
}
}
當我稱()改變