wpf MvvM INotifyPropertyChanged 的封装

 

1.用于wpf中 MvvM中, 属性双向通知的封装加工 成 一个方法

 /// 
    /// 对象的属性是可观察的基类
    /// 
    public class ObservableObject : INotifyPropertyChanged
    {
        #region 属性更改机制

        public event PropertyChangedEventHandler PropertyChanged;


       /// 
        /// 
        /// 
        /// 属性类型
        /// 被设置的属性
        /// 是否检查属性相等
        /// 将要设置的属性值
        /// 
        protected bool SetProperty(ref T storage, T value, bool isCheckEquals = true, [CallerMemberName] string propertyName = null)
        {
            if (isCheckEquals)
                if (object.Equals(storage, value)) { return false; }
            storage = value;
            this.OnPropertyChanged(propertyName);
            return true;
        }

        
        
        private void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var eventHandler = this.PropertyChanged;
            if (eventHandler != null)
            {
                eventHandler(this, new PropertyChangedEventArgs(propertyName));
            }
        }












    }

如图加工效果

       private double _actualAmount = INT_NUMBER_0;
        /// 
        /// 实际应收款
        /// 
        public double ActualAmount
        {
            get { return _actualAmount; }
            set { this.SetProperty(ref _actualAmount, value); }
        }

        private List _pharmacyInfoList = new List();

        public List PharmacyInfoList
        {
            get { return _pharmacyInfoList; }
            set { this.SetProperty(ref _pharmacyInfoList, value); }
        }

 

你可能感兴趣的:(wpf MvvM INotifyPropertyChanged 的封装)