语言

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 事件可以指示通过使用 PropertyChangedEventArgs 的 PropertyName 属性的 String.Empty 更改了对象上的所有属性。 请注意,不能像在 Windows Presentation Foundation (WPF) 和 Microsoft Silverlight 中那样使用 null。

适用于

另请参阅