Skip to content

Instantly share code, notes, and snippets.

@15mgm15
Last active January 23, 2019 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 15mgm15/2cb919ac2f663b3abef0400c96c7d417 to your computer and use it in GitHub Desktop.
Save 15mgm15/2cb919ac2f663b3abef0400c96c7d417 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Xamarin.Forms;
namespace XXXXXXXX
{
public class BaseViewModel : INotifyPropertyChanged
{
public INavigation Navigation { get; set; }
public BaseViewModel(INavigation navigation)
{
Navigation = navigation;
}
protected bool SetValue<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;
}
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
var changed = PropertyChanged;
if (changed == null)
return;
changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment