using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace MVVMDemo
{
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
///
/// 更新方式,其实只要下面的就行,在这边封装一层,更方便
///
///
///
///
///
protected void UpdateProperty(ref T properValue, T newValue, [CallerMemberName] string properName = "")
{
//对比新旧值,如果相等就不更新
if (object.Equals(properValue, newValue))
return;
properValue = newValue;
NotifyPropertyChanged(properName);
}
///
/// 最基础的方式
///
///
//public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)//参数加上此标记就可以不用传递参数了
public void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}