I have the following classes using Fody.PropertyChanged weaving:
[ImplementPropertyChanged]
public class OtherClass : INotifyPropertyChanged
{
#pragma warning disable 67
public event PropertyChangedEventHandler PropertyChanged;
#pragma warning restore 67
public int SomeValue { get; set; }
}
[ImplementPropertyChanged]
public class MyClass : INotifyPropertyChanged
{
#pragma warning disable 67
public event PropertyChangedEventHandler PropertyChanged;
#pragma warning restore 67
public string SomeText { get; set; }
public BindingList<OtherClass> Others { get; private set; }
public MyClass ()
{
Others = new BindingList<OtherClass>();
}
}
From a class consuming MyClass, I do not receive a PropertyChanged event.
What is wrong here?
Try adding the ListChanged event of the BindingList class to raise the PropertyChanged event:
public MyClass() {
this.Others = new BindingList<OtherClass>();
this.Others.ListChanged += Others_ListChanged;
}
void Others_ListChanged(object sender, ListChangedEventArgs e) {
if (this.PropertyChanged != null) {
this.PropertyChanged(this, new PropertyChangedEventArgs("Others"));
}
}
My OtherClass did not have to implement the INotifyPropertyChanged event:
[ImplementPropertyChanged]
public class OtherClass {
public int ID { get; set; }
}