求指点:遇到这样的事件无法触发的情况,不清楚原因:一个类A里包含一个list成员,类型为另外一个自定义类B,B里包含一个属性修改事件,这个A的对象修改list成员为什么不会触发属性修改事件。
public class A{
public List mylist=new List();
public A(){
for (int i = 0; i < 4; i++)
mylist.Add(new B());
}
}
public class B: INotifyPropertyChanged{
private string _Color;
public string Color {
get {
return _Color;
}
set {
_Color = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Color"));
Debug.WriteLine(_Color);//执行不到这里
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
pulic partial class Main{
public main(){
A a=new A();
a.mylist[0].PropertyChanged+=B_PropertyChanged;
a.mylist[0].Color="#123456";
}
private void B_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
Debug.WriteLine(e); //? not invoke?
}
}