INotifyPropertyChanged.PropertyChanged 事件

定义

在属性值更改时发生。

// 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 

事件类型

示例

此示例演示如何实现 INotifyPropertyChanged 接口,并在属性值更改时触发 PropertyChanged 事件。 有关完整的代码列表,请参阅 XAML 数据绑定示例

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

注解

使用 Microsoft .NET Framework生成 UWP 应用时,此接口是隐藏的,开发人员应使用 System.ComponentModel.INotifyPropertyChanged 接口。

PropertyChanged 事件可以通过对 PropertyChangedEventArgsPropertyName 属性使用 String.Empty 来指示对象上的所有属性都已更改。 请注意,不能像Windows Presentation Foundation (WPF) 和 Microsoft Silverlight 一样对此使用 null

适用于

另请参阅