Skip to content

Instantly share code, notes, and snippets.

@icebeam7
Created February 19, 2019 11:02
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 icebeam7/73dd6c3539821832cfd7f2a17829bd73 to your computer and use it in GitHub Desktop.
Save icebeam7/73dd6c3539821832cfd7f2a17829bd73 to your computer and use it in GitHub Desktop.
WeatherBotv4App - BaseViewModel.cs
using System.ComponentModel;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace WeatherBotv4App.ViewModels
{
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs((propertyName)));
}
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName]string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(storage, value))
{
return false;
}
storage = value;
OnPropertyChanged(propertyName);
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment