.NET Framework Class Library for Silverlight
INotifyPropertyChanged Interface

Notifies clients that a property value has changed.

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

Visual Basic (Declaration)
Public Interface INotifyPropertyChanged
Visual Basic (Usage)
Dim instance As INotifyPropertyChanged
C#
public interface INotifyPropertyChanged
Remarks

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.

Examples

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

Visual Basic
'Add Imports statements 
Imports System.ComponentModel
Imports System.Windows.Data


...


' Create a class that implements INotifyPropertyChanged 
Public Class Person
    Implements INotifyPropertyChanged

    Private firstNameValue As String
    Public Property FirstName() As String
        Get
            Return firstNameValue
        End Get
        Set(ByVal value As String)
            firstNameValue = value
            ' Call NotifyPropertyChanged when the property is updated 
            NotifyPropertyChanged("FirstName")
        End Set
    End Property

    ' Declare the PropertyChanged event 
    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

    ' NotifyPropertyChanged will raise the PropertyChanged event passing the 
    ' source property that is being updated. 
    Public Sub NotifyPropertyChanged(ByVal propertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    End Sub
End Class
C#
//Add using statements
using System.ComponentModel;
using System.Windows.Data;


...


// Create a class that implements INotifyPropertyChanged
public class Person : INotifyPropertyChanged
{
    private string firstNameValue;
    public string FirstName{
        get { return firstNameValue; }
        set
        {
            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));
        }
    }  
}
Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference

Other Resources

Tags :


Page view tracker