Back button on Xamarin Cross Platform

Asked

Viewed 1,230 times

0

How to make a function for when to click "Back" on Android in Xamarin, the app goes back to the previous screen ?

2 answers

1

On any Page, you can overwrite this method

    protected override bool OnBackButtonPressed()
    {
        return base.OnBackButtonPressed();
    }
  • it’s still not coming back, it’s like, I have a main view that when Click a button goes to the view I’m moving, then in case I need that when I click the back, go back to the previous view to mine

  • Show me your button event. If you’re using Pushasync for the new Page, it will automatically return when you click the Backbutton, you don’t even need to specify an event for this.

  • Ah, I’m not using Pushasync. I’ll take the test.

  • Are you doing how? Setting up Mainpage?

  • Do so, arrow the Mainpage as a Navigationpage (Your first page). Then on your button click you put Navigation.Pushasync (Your second page)

  • That @Marlon Ribeiro

  • it worked!! That’s right. Thank you.

  • Cool! Take a look at this post here that you will understand how the navigation works in Xamarin Forms. https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/hierarchical/

Show 3 more comments

1


Talking about Xamarin.Forms by "Cross Platform Xamarin", you must use the OnBackButtonPressed. But remembering as it says in the documentation:

The event is generated when the 'back' hardware button is pressed. This event is not generated on iOS.

Just replace this event on your Navigationpage and you’re ready to go:

protected override bool OnBackButtonPressed()
{    
    // A mágica acontece aqui
    return true;
}
  • I have a main View that when clicking a button goes to the view I’m moving, then in case I need that when I click the back, go back to the previous view to mine, got it ? Only this way is not coming back to her. It closes the app

Browser other questions tagged

You are not signed in. Login or sign up in order to post.