100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
.NET

INotifyPropertyChanged

Understand the interface that powers change notification in MVVM, how it wires up data binding, and how to implement it efficiently.

Data BindingBeginner8 min readJul 10, 2026
Analogies

Why Change Notification Is Necessary

INotifyPropertyChanged is a single-method interface (public event PropertyChangedEventHandler PropertyChanged) that a ViewModel implements so the data binding engine knows when a property's value has changed. Without it, a binding reads the property's value exactly once at binding time and never again, because the framework has no way to know the underlying data mutated — it can't poll every bound property every frame for performance reasons. By raising PropertyChanged with the property's name whenever a setter assigns a new value, the ViewModel actively tells any interested binding 'this property changed, come re-read it,' which is what makes the UI appear to update itself automatically.

🏏

Cricket analogy: INotifyPropertyChanged is like a stadium's PA announcer explicitly calling out 'wicket!' rather than fans having to keep glancing at the scoreboard every few seconds hoping to notice a change themselves.

Implementing INotifyPropertyChanged

A typical implementation declares the event, exposes a protected OnPropertyChanged helper method that raises it, and calls that helper from every property setter with the property's own name (using the nameof operator or the CallerMemberName attribute so the compiler infers the name automatically). Because nearly every ViewModel needs this boilerplate, it is almost always factored into a shared base class such as ViewModelBase or BindableBase (as in Prism) or ObservableObject (as in the CommunityToolkit.Mvvm library), so individual ViewModels only need to inherit from the base and call SetProperty or OnPropertyChanged rather than re-declaring the event and helper method in every class.

🏏

Cricket analogy: A shared ViewModelBase is like every franchise in the IPL following the same standard match-day protocol rather than each team inventing its own toss, review, and timeout rules from scratch.

csharp
public class ViewModelBase : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

    protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
    {
        if (EqualityComparer<T>.Default.Equals(field, value)) return false;
        field = value;
        OnPropertyChanged(propertyName);
        return true;
    }
}

public class CustomerViewModel : ViewModelBase
{
    private string _firstName;
    public string FirstName
    {
        get => _firstName;
        set => SetProperty(ref _firstName, value);
    }
}

Common Pitfalls

A frequent beginner mistake is mutating the backing field directly without calling OnPropertyChanged — the value changes internally, but the UI never learns about it because no event was raised. Another is misspelling the property name string in the older non-CallerMemberName style, for example OnPropertyChanged("FristName"), which silently breaks the binding for that property since WPF matches the notification against the exact string name. A third pitfall involves computed/derived properties: if TotalPrice is calculated from Quantity and UnitPrice, changing Quantity's setter must also explicitly call OnPropertyChanged(nameof(TotalPrice)), because the framework has no way to infer that dependency automatically.

🏏

Cricket analogy: Forgetting to raise the notification is like a fielder taking a clean catch but never signaling to the umpire — technically it happened, but without the signal, the wicket never gets recorded on the scoreboard.

Derived/computed properties are not automatically re-evaluated by bindings — if TotalPrice depends on Quantity, the Quantity setter must explicitly call OnPropertyChanged(nameof(TotalPrice)) in addition to notifying its own property, or the UI will show a stale total.

CallerMemberName eliminates magic strings: OnPropertyChanged([CallerMemberName] string propertyName = null) automatically receives the calling property's name at compile time, so a rename via IDE refactoring tools stays in sync automatically instead of leaving a stale string literal behind.

  • INotifyPropertyChanged exposes a single PropertyChanged event that tells the binding engine a property's value has changed.
  • Without raising PropertyChanged, a binding reads the source value once and never updates again after that.
  • CallerMemberName lets OnPropertyChanged infer the property name automatically, avoiding fragile magic-string literals.
  • Nearly every ViewModel implementation is factored into a shared base class (ViewModelBase, ObservableObject, BindableBase) to avoid repeating boilerplate.
  • Derived/computed properties need an explicit OnPropertyChanged call for their own name whenever a dependency's setter runs.
  • A misspelled property-name string silently breaks that property's binding with no compile-time or runtime error.
  • A SetProperty helper with an equality check avoids raising redundant notifications when the new value equals the old one.

Practice what you learned

Was this page helpful?

Topics covered

#NET#MVVMDesignPatternStudyNotes#MicrosoftTechnologies#INotifyPropertyChanged#Change#Notification#Necessary#Implementing#StudyNotes#SkillVeris