SHARE
TWEET

Untitled

a guest Sep 17th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// <summary>
  2.     /// A Base ViewModel
  3.     /// </summary>
  4.     public class BaseViewModel : INotifyPropertyChanged
  5.     {
  6.         bool isBusy = false;
  7.         /// <summary>
  8.         /// is it busy? i.e. doing something that may take long time
  9.         /// </summary>
  10.         public bool IsBusy
  11.         {
  12.             get { return isBusy; }
  13.             set => SetProperty(ref isBusy, value);
  14.         }
  15.  
  16.         string title = string.Empty;
  17.         /// <summary>
  18.         /// View Title
  19.         /// </summary>
  20.         public string Title
  21.         {
  22.             get { return title; }
  23.             set => SetProperty(ref title, value);
  24.         }
  25.  
  26.         /// <summary>
  27.         /// A reference to Navigation to Push and Pop pages
  28.         /// </summary>
  29.         public INavigation Navigation { get; }
  30.  
  31.         public BaseViewModel(INavigation navigation)
  32.         {
  33.             Navigation = navigation;
  34.         }
  35.  
  36.         /// <summary>
  37.         /// set the property and notify the change
  38.         /// </summary>
  39.         /// <typeparam name="T">Type</typeparam>
  40.         /// <param name="backingStore">local variable (field)</param>
  41.         /// <param name="value">new value</param>
  42.         /// <param name="propertyName">property name</param>
  43.         /// <param name="onChanged">action to raise</param>
  44.         /// <returns>was is successful?</returns>
  45.         protected bool SetProperty<T>(ref T backingStore, T value,
  46.             [CallerMemberName]string propertyName = "",
  47.             Action onChanged = null)
  48.         {
  49.             if (EqualityComparer<T>.Default.Equals(backingStore, value))
  50.                 return false;
  51.  
  52.             backingStore = value;
  53.             onChanged?.Invoke();
  54.             OnPropertyChanged(propertyName);
  55.             return true;
  56.         }
  57.  
  58.         #region INotifyPropertyChanged
  59.         public event PropertyChangedEventHandler PropertyChanged;
  60.         protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
  61.         {
  62.             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  63.         }
  64.         #endregion
  65.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top