The problem is that Microsoft didn’t provide any official way closing a Silverlight application, since working with the Metro style UX concept, the user should press the Back key, closing the application by himself.
You can argue with me about this concept, but this is not the place for discussing it. You may read further about it here.
This post is going to provide a simple and correct way of asking the user to close the application, leaving him no other option.
But first, you should know that technically, any Windows Phone application could be closed as following:
1. Throwing an exception from, let say: button click handler. The application’s unhandled-exception handler will catch it and silently close the application.
2. Create an instance of type Microsoft.Xna.Framework.Game and call Exit: new Microsoft.Xna.Framework.Game().Exit();
3. Clear the entire back-stack, and then click NavigationService.GoBack(). Again,. this will throw an exception saying the you can’t call GoBack while CanGoBack returns false.
– NOTE: There is no guarantee that Microsoft will like these options, and your application may be rejected by the Marketplace verification process.
The concept of asking the user to exit the application is simple. All you have to do is ask politely to press the back button for exit, lets say for maintenance or some other reason.
So here’s how:
1. In the place you want the user to exit, navigate to a special page, asking the user to click the Back button.
2. In this page navigated-to event handler, clear all entries from the back-stack, so pressing the back button will exit the application.
You can download the sample code from here.