1.用于wpf中 MvvM中, 属性双向通知的封装加工 成 一个方法
/// <summary>
/// 对象的属性是可观察的基类
/// </summary>
public class ObservableObject : INotifyPropertyChanged
{
#region 属性更改机制
public event PropertyChangedEventHandler PropertyChanged;
/// </summary>
///
/// </summary>
/// <typeparam name="T">属性类型</typeparam>
/// <param name="storage">被设置的属性</param>
/// <param name="isCheckEquals">是否检查属性相等</param>
/// <param name="value">将要设置的属性值</param>
/// <returns></returns>
protected bool SetProperty<T>(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;
/// <summary>
/// 实际应收款
/// </summary>
public double ActualAmount
{
get { return _actualAmount; }
set { this.SetProperty(ref _actualAmount, value); }
}
private List<PharmacyInfo> _pharmacyInfoList = new List<PharmacyInfo>();
public List<PharmacyInfo> PharmacyInfoList
{
get { return _pharmacyInfoList; }
set { this.SetProperty(ref _pharmacyInfoList, value); }
}