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.

57 lines
1.5 KiB

1 year ago
  1. using System.ComponentModel;
  2. using System.Runtime.CompilerServices;
  3. namespace GMCabsDriverAssistantSolution.ViewModels
  4. {
  5. public class BaseViewModel : INotifyPropertyChanged
  6. {
  7. #region Fields
  8. private bool isBusy = false;
  9. private string title = string.Empty;
  10. #endregion
  11. #region Properties
  12. public bool IsBusy
  13. {
  14. get => isBusy;
  15. set => SetProperty(ref isBusy, value);
  16. }
  17. public string Title
  18. {
  19. get => title;
  20. set => SetProperty(ref title, value);
  21. }
  22. #endregion
  23. protected bool SetProperty<T>(ref T backingStore, T value,
  24. [CallerMemberName] string propertyName = "",
  25. Action onChanged = null)
  26. {
  27. if (EqualityComparer<T>.Default.Equals(backingStore, value))
  28. {
  29. return false;
  30. }
  31. backingStore = value;
  32. onChanged?.Invoke();
  33. OnPropertyChanged(propertyName);
  34. return true;
  35. }
  36. #region INotifyPropertyChanged
  37. public event PropertyChangedEventHandler PropertyChanged;
  38. protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
  39. {
  40. var changed = PropertyChanged;
  41. if (changed == null)
  42. {
  43. return;
  44. }
  45. changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
  46. }
  47. #endregion
  48. }
  49. }