bitwarden-android/src/App/Pages/BaseViewModel.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2019-03-29 00:10:10 +03:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
2019-03-29 06:52:33 +03:00
namespace Bit.App.Pages
2019-03-29 00:10:10 +03:00
{
public abstract class BaseViewModel : INotifyPropertyChanged
{
private string _pageTitle = string.Empty;
public event PropertyChangedEventHandler PropertyChanged;
public string PageTitle
{
get => _pageTitle;
set => SetProperty(ref _pageTitle, value);
}
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;
}
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}