20240301_JSEQ_upperpc/JiangsuEarthquakeNow/JiangsuEarthquake/Common/NotifyBase.cs
XuMin 3b6c570800 1 经过电控腔测试和升压站测试;
2 解决了后一个通信连接会影响前一个通信连接的问题;
3 测试过程中存在的问题修改;
2024-09-03 16:30:34 +08:00

45 lines
1.6 KiB
C#

using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace JiangsuEarthquake.Common
{
public class NotifyBase : ObservableObject,INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
//[CallerMemberName]string propName = "" 设置一个默认值 提高容错性
public void DoNotify([CallerMemberName] string propName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
}
/// <summary>
/// Sets property if it does not equal existing value. Notifies listeners if change occurs.
/// </summary>
/// <typeparam name="T">Type of property.</typeparam>
/// <param name="member">The property's backing field.</param>
/// <param name="value">The new value.</param>
/// <param name="propertyName">Name of the property used to notify listeners. This
/// value is optional and can be provided automatically when invoked from compilers
/// that support <see cref="CallerMemberNameAttribute"/>.</param>
protected virtual bool SetProperty<T>(ref T member, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(member, value))
{
return false;
}
member = value;
DoNotify(propertyName);
return true;
}
}
}