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