PostSharp.ILINotify­Property­Changed
Open sandboxFocusImprove this doc

INotifyPropertyChanged

Binding objects to the UI is a large and tedious task. You must implement <xref:System.ComponentModel.INotifyPropertyChanged> on every property that needs to be bound. You need to ensure that the underlying property setter correctly raises events so that the View knows that changes have occurred. The larger your codebase, the more work there is. You can partially eliminate all of this repetitive code by pushing some of the functionality to a base class that each Model class inherits from. It still doesn't eliminate all of the repetition though.

PostSharp can completely eliminate all of that repetition for you. PostSharp's NotifyPropertyChangedAttribute has the following features and benefits:

  • Supports computed properties.

  • Supports computed properties referencing child objects, e.g. string FullName => this.model.FirstName + " " + this.model.LastName.

  • Raises the PropertyChanged at the right moment, when all class invariants are valid.

  • Fully customizable. Can be integrated with other MVVM frameworks.

  • High-performance. Almost as fast as handwritten code.

In this chapter

Topic Description
Implementing INotifyPropertyChanged This section shows how to automatically implement the <xref:System.ComponentModel.INotifyPropertyChanged> interface in a class thanks to the NotifyPropertyChangedAttribute aspect.
Implementing INotifyPropertyChanged with Properties that Depend on Other Objects This section describes how to handle dependencies that cross several objects, as when a view-model object is dependent on properties of a model object.
Implementing INotifyPropertyChanging This section documents how to implement the INotifyPropertyChanging interface for components which need to be signalled before a property value is changed.
Integrating the NotifyPropertyChanged Aspect with UI Frameworks This section shows examples of using the NotifyPropertyChangedAttribute aspect with some of the popular UI frameworks.
Handling Corner Cases of the NotifyPropertyChanged Aspect This section documents how to cope with the cases that cannot be automatically handled by the NotifyPropertyChangedAttribute aspect.
Understanding the NotifyPropertyChanged Aspect This section describes the principles and concepts on which the NotifyPropertyChangedAttribute aspect relies.
Suppressing False Positives of the NotifyPropertyChanged Aspect This section shows how to prevent notifications when the property value does not actually change.