This documentation is archived and is not being maintained.

INotifyPropertyChanged.PropertyChanged Event

Occurs when a property value changes.

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

Event PropertyChanged As PropertyChangedEventHandler
Dim instance As INotifyPropertyChanged 
Dim handler As PropertyChangedEventHandler 

AddHandler instance.PropertyChanged, handler

The PropertyChanged event can indicate all properties on the object have changed by using either Nothing or String.Empty as the property name in the PropertyChangedEventArgs.

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

' This class implements a simple customer type  
' that implements the IPropertyChange interface. 

Public Class DemoCustomer
    Implements INotifyPropertyChanged

    ' These fields hold the values for the public properties. 
    Private idValue As Guid = Guid.NewGuid()
    Private customerNameValue As String = String.Empty
    Private phoneNumberValue As String = String.Empty

    Public Event PropertyChanged As PropertyChangedEventHandler _
        Implements INotifyPropertyChanged.PropertyChanged

    Private Sub NotifyPropertyChanged(ByVal info As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    End Sub 

    ' The constructor is private to enforce the factory pattern. 
    Private Sub New()
        customerNameValue = "Customer"
        phoneNumberValue = "(555)555-5555" 

    End Sub 

    ' This is the public factory method. 
    Public Shared Function CreateNewCustomer() As DemoCustomer
        Return New DemoCustomer()

    End Function 

    ' This property represents an ID, suitable 
    ' for use as a primary key in a database. 
    Public ReadOnly Property ID() As Guid
            Return Me.idValue
        End Get 
    End Property 

    Public Property CustomerName() As String 
            Return Me.customerNameValue
        End Get 

        Set(ByVal value As String)
            If Not (value = customerNameValue) Then 
                Me.customerNameValue = value
            End If 
        End Set 
    End Property 

    Public Property PhoneNumber() As String 
            Return Me.phoneNumberValue
        End Get 

        Set(ByVal value As String)
            If Not (value = phoneNumberValue) Then 
                Me.phoneNumberValue = value
            End If 

        End Set 
    End Property 
End Class

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0