You have to set the BackPressedEventArgs.Handled property to true. If your app is at its first page and can't navigate backwards, you should not handle the event and the operating system will suspend your app.
First you have to enable the NavigationCacheMode and then add an event handler for back button press to OnNavigatedTo method of the page and in the method you can navigate to back page by using the navigation stack.
Here is the complete code for that.
public BlankPage2()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Enabled;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
HardwareButtons.BackPressed += this.HardwareButtons_BackPressed;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
HardwareButtons.BackPressed -= this.HardwareButtons_BackPressed;
}
private void HardwareButtons_BackPressed(object sender,BackPressedEventArgs e)
{
Frame frame = Window.Current.Content as Frame;
if (frame == null)
{
return;
}
if (frame.CanGoBack)
{
frame.GoBack();
e.Handled = true;
}
}