Skip to content

Instantly share code, notes, and snippets.

@devjaime
Created April 17, 2019 04:45
Show Gist options
  • Select an option

  • Save devjaime/21875b7351a0b074d6164d83fce00b4c to your computer and use it in GitHub Desktop.

Select an option

Save devjaime/21875b7351a0b074d6164d83fce00b4c to your computer and use it in GitHub Desktop.
BasePage
using System.Threading.Tasks;
using Acelerometro.ViewModel;
using Xamarin.Forms;
namespace Acelerometro.View
{
public class BasePage : ContentPage
{
public BasePage()
{
NavigationPage.SetBackButtonTitle(this, "Atras");
}
protected override void OnAppearing()
{
base.OnAppearing();
SetupBinding(BindingContext);
}
protected override void OnDisappearing()
{
TearDownBinding(BindingContext);
base.OnDisappearing();
}
protected void SetupBinding(object bindingContext)
{
if (bindingContext is BaseViewModel vm)
{
vm.DoDisplayAlert += OnDisplayAlert;
vm.OnAppearing();
}
}
protected void TearDownBinding(object bindingContext)
{
if (bindingContext is BaseViewModel vm)
{
vm.OnDisappearing();
vm.DoDisplayAlert -= OnDisplayAlert;
}
}
Task OnDisplayAlert(string message)
{
return DisplayAlert(Title, message, "OK");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment