How to disable Hardware Back button in Windows Phone App

Sometimes there may be a situation when you wish to prompt the user before exiting the page or frame of the application. So you need to control the back button function at that time.

Here is the code to disable the back button and perform your own function on pressing the back button.

 

Silverlight (Windows phone 8/8.1)

In the constructor of the page you need to add the following code as shown in the figure below

 


 

For example you wish to prompt the user before exiting the app then you can add the following code on your MainPage.

 

 

WinRT (Windows phone 8.1/10)

In the constructor of the page or frame you need to add the following code as shown in the figure below

 


 

 

I hope this post will be helpful to you


Handling the Back Button in a Windows Phone 8.1 app

If you are developing an app using the Universal app template then you may have noticed that the app terminates on pressing the hardware back button.
Lets navigate from Page1.xaml to Page2.xaml by using a button with the click event code:

this.Frame.Navigate(typeof(Page2));

When we are on Page2, and the hardware back button is used, the app closes without an exception or anything. It just returns to the start screen. This is new to Windows Phone 8.1. If you create a new Hub Universal App using a VS2013 template, you’ll notice a class in Common folder called a NavigationHelper.
This NavigationHelper gives you a hint how to properly react to back button press. So, if you don’t want to use the NavigationHelper, here’s how to get the old behavior back:

You can also do it on app level, to avoid having to do it on every page:

 
if you wish to disable the back button in your application you can view the following post
 
How to disable Hardware Back button in Windows Phone App