Share via


INotifyPropertyChanged.PropertyChanged Event

Definition

Occurs when a property value changes.

// Register
event_token PropertyChanged(PropertyChangedEventHandler const& handler) const;

// Revoke with event_token
void PropertyChanged(event_token const* cookie) const;

// Revoke with event_revoker
INotifyPropertyChanged::PropertyChanged_revoker PropertyChanged(auto_revoke_t, PropertyChangedEventHandler const& handler) const;
event PropertyChangedEventHandler PropertyChanged;
function onPropertyChanged(eventArgs) { /* Your code */ }
iNotifyPropertyChanged.addEventListener("propertychanged", onPropertyChanged);
iNotifyPropertyChanged.removeEventListener("propertychanged", onPropertyChanged);
- or -
iNotifyPropertyChanged.onpropertychanged = onPropertyChanged;
Event PropertyChanged As PropertyChangedEventHandler 

Event Type

Examples

This example demonstrates how to implement the INotifyPropertyChanged interface and fire the PropertyChanged event whenever property values change. For the complete code listing, see the XAML data binding sample.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataBinding
{
    public class Employee : INotifyPropertyChanged 
    {
        private string _name;
        private string _organization;

        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                RaisePropertyChanged("Name");
            }
        }

        public string Organization
        {
            get { return _organization; }
            set
            {
                _organization = value;
                RaisePropertyChanged("Organization");
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;
        protected void RaisePropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
    }
}

Remarks

When building UWP app with the Microsoft .NET Framework, this interface is hidden and developers should use the System.ComponentModel.INotifyPropertyChanged interface.

The PropertyChanged event can indicate that all properties on the object have changed by using String.Empty for the PropertyName property of the PropertyChangedEventArgs. Note that you cannot use null for this like you can in Windows Presentation Foundation (WPF) and Microsoft Silverlight.

Applies to

See also