There is quite a bit written on how to handle tombstoning on a Windows Phone. Most of the guidance is for code-behind developers. Here is an MSDN article (How to: Preserve and Restore Page State for Windows Phone) that shows how to use the Page’s OnNavigatedTo and OnNavigatedFrom methods to preserve and restore page state. This article proposes using an instance variable (_isNewPageInstance) to distinguish between navigating to the page due to dormancy or tombstoning.
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e){ // If _isNewPageInstance is true, the page constuctor has been called, so // state may need to be restored. if (_isNewPageInstance) { if (_viewModel == null) { if (State.Count > 0) { _viewModel = (ViewModel)State["ViewModel"]; } else { _viewModel = new ViewModel(); } } DataContext = _viewModel; } // Set _isNewPageInstance to false. If the user navigates back to this page // and it has remained in memory, this value will continue to be false. _isNewPageInstance = false;}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e){ var viewModel = (MyViewModel) this.DataContext; viewModel.OnNavigatedTo(e, this.State);}
Please take a look and give us feedback.