Hi,
I'm trying to understand how OnBackButtonPressed works because I set the breakpoint in that method but it's never hit. I have two pages - PageOneView ** and **PageTwoView. In App.cs, I set PageOneView to be a mainpage and wrap it with NavigationPage(). PageOnView has a button to go to PageTwoView.
Here are my code.
App.cs
public class App : Application
{
public App()
{
// The root page of your application
MainPage = new NavigationPage(new PageOneView());
}
}
PageOneView.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="NavigationBackButton.Views.PageOneView"
Title="ONE">
<StackLayout>
<Button Text="Go to Page Two" Clicked="Button_OnClicked"/>
<Label Text="One" VerticalOptions="Center" HorizontalOptions="Center" />
</StackLayout>
</ContentPage>
PageOneView.xaml.cs
public partial class PageOneView : ContentPage
{
public PageOneView()
{
InitializeComponent();
}
private void Button_OnClicked(object sender, EventArgs e)
{
Navigation.PushAsync(new PageTwoView(), true);
}
protected override bool OnBackButtonPressed()
{
Debug.WriteLine(">>>> PageOneView:Back button pressed"); //***** Never Hit here *****
return base.OnBackButtonPressed();
}
}
PageTwoView.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="NavigationBackButton.Views.PageTwoView"
Title="TWO">
<Label Text="TWO" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>
PageTwoView.xaml.cs
public partial class PageTwoView : ContentPage
{
public PageTwoView()
{
InitializeComponent();
}
protected override bool OnBackButtonPressed()
{
Debug.WriteLine(">>>> PageTwoView:Back button pressed"); //***** Never Hit here *****
return base.OnBackButtonPressed();
}
}
Any suggestions?
Thanks,
Jay