当前位置:   article > 正文

WPF 属性通知接口实现 INotifyPropertyChanged_wpf中notification接口

wpf中notification接口

WPF 属性通知接口实现 INotifyPropertyChanged

 	/// <summary>
    /// 属性改变通知类
    /// </summary>
    public class PropertyNotifyBase : INotifyPropertyChanged
    {
        /// <summary>
        /// 属性改变事件
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// 更新属性
        /// </summary>
        /// <typeparam name="T">属性类型</typeparam>
        /// <param name="propertyValue">属性值</param>
        /// <param name="newValue">新值</param>
        /// <param name="propertyName">属性名称</param>
        public void UpdateProperty<T>(ref T propertyValue, T newValue, [CallerMemberName]string propertyName = "")
        {
            if (!object.Equals(propertyValue, newValue))
            {
                propertyValue = newValue;
                UpdateProperty(propertyName);
            }
        }

        /// <summary>
        /// 更新属性
        /// </summary>
        /// <param name="propertyName">属性名称</param>
        protected void UpdateProperty(string propertyName)
        {
            if (this.PropertyChanged != null) this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/567793
推荐阅读
  

闽ICP备14008679号