Click here to Skip to main content
12,758,782 members (33,013 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 29 Mar 2011

WP7 TombstoneHelper

, 29 Mar 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
What data to save when your application is tombstoned.

“The procedure in which the Operating System terminates an application’s process when the user navigates away from the application. The Operating System maintains state information about the application. If the user navigates back to the application, the Operating System restarts the application process and passes the state data back to the application.”

When your application gets tombstoned, you get an opportunity to save some state about your application… Common questions I get are what should I save, where should I save it and when? Let me try and address some of these questions:

What should I save

  • Panorama: Panorama.SelectedIndex
  • Pivot: Pivot.SelectedIndex
  • ListBox: ScrollViewer.VerticalOffset and ScrollViewer.HorizontalOffset
  • TextBox: TextBox.Text, TextBox.SelectionStart, and TextBox.SelectionLength
  • CheckBox: CheckBox.IsChecked
  • RadioButton: RadioButton.IsChecked
  • Slider: Slider.Value

Where should I save it

Each page has a State dictionary and their is also an application-wide dictionary as part of the PhoneApplicationService. These state dictionaries get automatically persisted when tombstoned! The helper class will save each control that you give to it on the page specific dictionary, and it will use the control's name as the key!

When should I save it

The last question is when? You have two options here… Application lifecycle events (Application_Activated and Application_Deactivated), or on a page level, you can override OnNavigateTo and OnNavigateFrom!

Since the helper class really tries and addresses page specific state, it makes sense that we will be using OnNavigateTo/OnNavigateFrom!

Let's try it out…

The helpers are implemented as extension methods so all you have to do is:

public partial class NormalPage : PhoneApplicationPage
    public NormalPage()

    protected override void OnNavigatedFrom(
       System.Windows.Navigation.NavigationEventArgs e)


    protected override void OnNavigatedTo(
      System.Windows.Navigation.NavigationEventArgs e)


Easy, isn’t it!

Here is the sample application.

Read more about the Windows Phone execution model here:


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

South Africa South Africa
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Mr.Jinky11-Aug-11 4:08
memberMr.Jinky11-Aug-11 4:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 29 Mar 2011
Article Copyright 2011 by rudigrobler
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid