I was never sure about the meaning of propertyName
when implementing INotifyPropertyChanged
. So generally you implement INotifyPropertyChanged
as:
public class Data : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName = "") {
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
private string itsID;
public string ID {
get { return itsID; }
set {
if (itsID != value) {
itsID = value;
NotifyPropertyChanged("ID");
}
}
}
I was never sure about the propertyName
argument to NotifyPropertyChanged(string propertyName)
.
- Can that be any arbitrary string (like "MyID" in the above example)?
- Or does .NET use Reflection to align it with a property in a class so it has to match the name of the property exactly?
- What if the
propertyName
doesn't match the name of theProperty
exactly, does .NET consider the entire object aschanged
?