Denis Denis - 4 months ago 43
C# Question

INotifyPropertyChanged and propertyName

I was never sure about the meaning of

when implementing
. So generally you implement

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;

I was never sure about the
argument to
NotifyPropertyChanged(string propertyName)

  1. Can that be any arbitrary string (like "MyID" in the above example)?

  2. 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?

  3. What if the
    doesn't match the name of the
    exactly, does .NET consider the entire object as

hvd hvd

It's not .NET Framework itself per se, it's pretty much every PropertyChanged subscriber out there (some of which do indeed happen to be distributed as part of the framework) that assumes you use the interface as intended, by sending the property name. If you send a notification that the property MyID has changed, when another component is looking at the property ID, it will typically see the notification, compare the names, and conclude "this notification isn't for me".