I have 2 page, MainPage and SettingsPage. In the MainPage there is a button that when clicked it allows to get to the SettingsPage using this code:
Frame.Navigate(typeof(SettingsPage));
Now I want that on the second page when the user clicks the back button the application go back to the MainPage.
I've tried by adding the following code:
public SettingsPage()
{
this.InitializeComponent();
SystemNavigationManager.GetForCurrentView().BackRequested += SettingsPage_BackRequested;
}
private void SettingsPage_BackRequested(object sender, BackRequestedEventArgs e)
{
if (this.Frame.CanGoBack)
{
this.Frame.GoBack();
}
e.Handled = true;
}
The application go back to the MainPage but the SettingsPage_BackRequested event continues to work so if I click the back button on the MainPage the app doesn't close.
How can i handle the backbutton in my application?