You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.4 KiB
42 lines
1.4 KiB
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;
|
|
|
|
/// <summary>
|
|
/// 更新方式,其实只要下面的就行,在这边封装一层,更方便
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="properValue"></param>
|
|
/// <param name="newValue"></param>
|
|
/// <param name="properName"></param>
|
|
protected void UpdateProperty<T>(ref T properValue, T newValue, [CallerMemberName] string properName = "")
|
|
{
|
|
//对比新旧值,如果相等就不更新
|
|
if (object.Equals(properValue, newValue))
|
|
return;
|
|
properValue = newValue;
|
|
NotifyPropertyChanged(properName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 最基础的方式
|
|
/// </summary>
|
|
/// <param name="propertyName"></param>
|
|
//public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)//参数加上此标记就可以不用传递参数了
|
|
public void NotifyPropertyChanged(string propertyName)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
}
|
|
}
|