Export (0) Print
Expand All

INotifyPropertyChanged.PropertyChanged Event

Occurs when a property value changes.

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

'Declaration
Event PropertyChanged As PropertyChangedEventHandler
'Usage
Dim instance As INotifyPropertyChanged
Dim handler As PropertyChangedEventHandler

AddHandler instance.PropertyChanged, handler

/** @event */
void add_PropertyChanged (PropertyChangedEventHandler value)

/** @event */
void remove_PropertyChanged (PropertyChangedEventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

The PropertyChanged event can indicate all properties on the object have changed by using either a null reference (Nothing in Visual Basic) 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 customerName As String = String.Empty
    Private companyNameValue 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() 
        customerName = "no data"
        companyNameValue = "no data"
        phoneNumberValue = "no data"
    
    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
        Get
            Return Me.idValue
        End Get
    End Property
    
    
    Public Property CompanyName() As String 
        Get
            Return Me.companyNameValue
        End Get
        
        Set(ByVal value As String)
            If Not (value = companyNameValue) Then
                Me.companyNameValue = value
                NotifyPropertyChanged("CompanyName")
            End If
        End Set
    End Property
    
    
    Public Property PhoneNumber() As String 
        Get
            Return Me.phoneNumberValue
        End Get
        
        Set(ByVal value As String)
            If Not (value = phoneNumberValue) Then
                Me.phoneNumberValue = value
                NotifyPropertyChanged("PhoneNumber")
            End If

        End Set
    End Property
End Class

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft