Skip to content

Commit

Permalink
ViewModelBase新增方法
Browse files Browse the repository at this point in the history
  • Loading branch information
huuhghhgyg committed Sep 4, 2022
1 parent 72b065d commit 040f40d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Chamberlain_UWP/Backup/ViewModel/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -15,5 +16,15 @@ protected virtual void OnPropertyChanged(string propertyName)
PropertyChangedEventHandler handler = this. PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
public bool Set<T>(ref T target, T value, [CallerMemberName] string propertyName = null)
{
//如果value无变化
if(EqualityComparer<T>.Default.Equals(target, value)) return false;

//目标值与value不同
target = value;
OnPropertyChanged(propertyName);
return true;
}
}
}

0 comments on commit 040f40d

Please sign in to comment.