INotifyPropertyChanged INotifyPropertyChanged INotifyPropertyChanged Interface

Definition

Notifies clients that a property value has changed.

.NET This interface appears as System.ComponentModel.INotifyPropertyChanged.

public interface INotifyPropertyChangedpublic interface INotifyPropertyChangedPublic Interface INotifyPropertyChanged
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

When programming with .NET, this interface is hidden and developers should use the System.ComponentModel.INotifyPropertyChanged interface.

The INotifyPropertyChanged interface is used to notify clients, typically binding clients, that a property value has changed. For example, consider an Employee object with a property called Name. To provide generic property-change notification, the Employee type implements the INotifyPropertyChanged interface and raises a PropertyChanged event when Name is changed.

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 (Nothing in Microsoft Visual Basic) for this like you can in Windows Presentation Foundation (WPF) and Microsoft Silverlight.

The PropertyChanged event can indicate that indexer properties on the object have changed by using a PropertyName value of "Item[indexer ]" for specific indexers or "Item[]" for all indexers. Note that C++ does not currently support binding to indexers. For a workaround, see the XAML data binding sample.

Events

PropertyChanged PropertyChanged PropertyChanged

Occurs when a property value changes.

public abstract event PropertyChangedEventHandler PropertyChangedpublic abstract event PropertyChangedEventHandler PropertyChangedPublic MustInherit Event PropertyChanged
Attributes

Remarks

When building Windows Store 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.

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));
            }
        }
    }
}
See Also

See Also