INotifyPropertyChanged Interface

July 28, 2014

Notifies clients that a property value has changed.

Namespace:  System.ComponentModel
Assembly:  System (in System.dll)

public interface INotifyPropertyChanged

The INotifyPropertyChanged type exposes the following members.

  NameDescription
Public eventPropertyChangedOccurs when a property value changes.
Top

The INotifyPropertyChanged interface is used to notify clients, typically binding clients, that a property value has changed.

For example, consider a Person object with a property called FirstName. To provide generic property-change notification, the Person type implements the INotifyPropertyChanged interface and raises a PropertyChanged event when FirstName is changed.

The following code example demonstrates the how to implement the INotifyPropertyChanged interface.


//Add using statements
using System.ComponentModel;
using Microsoft.Phone.Controls;


...


// Create a class that implements INotifyPropertyChanged
public class Person : INotifyPropertyChanged
{
    private string firstNameValue;

    public string FirstName{
        get { return firstNameValue; }

        set
        {
            // Only update value if it changed
            if (value != firstNameValue)
            {
                firstNameValue = value;

                // Call NotifyPropertyChanged when the property is updated
                NotifyPropertyChanged("FirstName");
            }
        }
    }

    // Declare the PropertyChanged event
    public event PropertyChangedEventHandler PropertyChanged;

    // NotifyPropertyChanged will raise the PropertyChanged event passing the
    // source property that is being updated.
    public void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }  
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft