-
-
Save devjaime/21875b7351a0b074d6164d83fce00b4c to your computer and use it in GitHub Desktop.
BasePage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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