Skip to content

Instantly share code, notes, and snippets.

@nord-
Created August 14, 2019 11:20
Show Gist options
  • Save nord-/012a3f0a9d82ffbb4efaeb5d9c635346 to your computer and use it in GitHub Desktop.
Save nord-/012a3f0a9d82ffbb4efaeb5d9c635346 to your computer and use it in GitHub Desktop.
ContentPage base class for Xamarin Forms
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Xamarin.Forms;
namespace ChargeNode
{
public class ContentPageBase<T> : ContentPage where T : PageViewModelBase
{
protected T PageViewModel
{
get => BindingContext as T;
set => BindingContext = value;
}
}
public abstract class PageViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment