• WPF 自定义NotifyPropertyChanged


    该工具类实现INotifyPropertyChanged接口

    复制代码
        /// <summary>
        /// 实现了属性更改通知的基类
        /// </summary>
        public class BaseNotifyPropertyChanged : System.ComponentModel.INotifyPropertyChanged
        {
            /// <summary>
            /// 属性值变化时发生
            /// </summary>
            /// <param name="propertyName"></param>
            protected virtual void OnPropertyChanged(string propertyName)
            {
                if (this.PropertyChanged != null)
                    this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
    
            /// <summary>
            /// 属性值变化时发生
            /// </summary>
            /// <param name="propertyName"></param>
            protected virtual void OnPropertyChanged<T>(Expression<Func<T>> propertyExpression)
            {
                var propertyName = (propertyExpression.Body as MemberExpression).Member.Name;
                this.OnPropertyChanged(propertyName);
            }
    
            public virtual event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
        }
    复制代码

    使用时继承此类,然后在VM中的属性get使用:OnPropertyChanged(()=>PropertyName)  ??难道不是应该Set

  • 相关阅读:
    5.14事务
    5.13Mysql数据库Database
    未来打算
    浅谈P NP NPC
    1222
    1219
    Linux初等命令
    惩罚因子(penalty term)与损失函数(loss function)
    12 14
    java 泛型思考
  • 原文地址:https://www.cnblogs.com/sjqq/p/8458369.html
Copyright © 2020-2023  润新知