Exiting a Windows Phone Application

less than 1 minute read

On a Windows Phone it’s bad form to quit an application to close itself. Apps are supposed to be left running, since the application lifecycle suspends apps when they are not in use. Pressing the “Back” key on the first page will close your app.

So, for times when that app should no longer be used disabling the UI is the next best thing to exiting the application. Here’s an easy way to do it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private void Exit()
{
    while (NavigationService.BackStack.Any())
    {
            NavigationService.RemoveBackEntry();
    }
    this.IsHitTestVisible = this.IsEnabled = false;
    if (this.ApplicationBar != null)
    {
	    foreach (var item in this.ApplicationBar.Buttons.OfType<ApplicationBarIconButton>())
	    {
		     item.IsEnabled = false;
        }
    }
}

Updated: