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


Chetan Gulati

Currently am doing B TECH in IT from Delhi Technological University. App development is my passion. Believe in quality rather than quantity.

Read more:
How to create your first Windows Phone app
How to change the App name and Tile name of your Windows phone app
Data binding in Windows Phone app – One way binding
Close