Skip to content

Instantly share code, notes, and snippets.

@RedTahr
Last active January 27, 2016 19:25
Show Gist options
  • Save RedTahr/92abca6781cde7813a26 to your computer and use it in GitHub Desktop.
Save RedTahr/92abca6781cde7813a26 to your computer and use it in GitHub Desktop.
Xamarin.Forms BaseViewModel
namespace ... {
public abstract class BaseViewModel : BindableObject { // yeah its overkill, can't recall why my colleague did it this way
private string title = string.Empty;
public string Title {
get { return title; }
set {
if(title != value) {
title = value;
RaisePropertyChanged();
}
}
}
//private string icon = null;
//public string Icon {
// get { return icon; }
// set {
// if (icon != value) {
// icon = value;
// RaisePropertyChanged();
// }
// }
//}
private bool isBusy = false;
public const string IsBusyPropertyName = "IsBusy";
public bool IsBusy {
get { return isBusy; }
set {
if (isBusy != value) {
isBusy = value;
RaisePropertyChanged();
}
}
}
// an idea from XLabs
public virtual void OnAppearing() { }
public virtual void OnDisappearing() { }
// from a C# book, o'Reaillys in a nutshell I think it was.
internal void RaisePropertyChanged([CallerMemberName] string propertyName = null) {
OnPropertyChanged(propertyName);
}
// from Chris Riesgo's CarouselView Layout
//protected void SetObservableProperty<T>(
// ref T field,
// T value,
// [CallerMemberName] string propertyName = "") {
// if (EqualityComparer<T>.Default.Equals(field, value)) return;
// field = value;
// OnPropertyChanged(propertyName);
//}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment