Created
November 20, 2023 10:15
-
-
Save somapatrik/cc11959e528d3b6a94451e51f25bfb78 to your computer and use it in GitHub Desktop.
ViewModel parent class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PrimeViewModel : INotifyPropertyChanged | |
{ | |
protected bool SetProperty<T>(ref T backingStore, T value, | |
[CallerMemberName] string propertyName = "", | |
Action onChanged = null) | |
{ | |
if (EqualityComparer<T>.Default.Equals(backingStore, value)) | |
return false; | |
backingStore = value; | |
onChanged?.Invoke(); | |
OnPropertyChanged(propertyName); | |
return true; | |
} | |
public event PropertyChangedEventHandler PropertyChanged; | |
protected void OnPropertyChanged([CallerMemberName] string propertyName = "") | |
{ | |
var changed = PropertyChanged; | |
if (changed == null) | |
return; | |
changed.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment