×
Namespaces

Variants
Actions
(Difference between revisions)

Tombstoning helper for Windows Phone 7

From Nokia Developer Wiki
Jump to: navigation, search
riussi (Talk | contribs)
(Riussi -)
hamishwillee (Talk | contribs)
m (moved Autotombstone helper to Tombstoning helper for Windows Phone 7: It is useful to include the software platform or development environment in the title.)

Revision as of 04:24, 13 August 2012

This article explains how to use tombstone helper to persist your pages data between navigation

WP Metro Icon File.png
SignpostIcon XAML 40.png
SignpostIcon WP7 70px.png
Article Metadata
Compatibility
Platform(s): Windows Phone 7
Windows Phone 7.5
Article
Keywords: tombstoning, wp7
Created: riussi (11 Aug 2012)
Last edited: hamishwillee (13 Aug 2012)

Introduction

Tombstone helper is a small helper to ease your life in persisting your pages' data when tombstoning occurs in Windows Phone 7.

Setup

  1. Download the TombstoneHelper.dll from CodePlex
  2. Add a reference to it in your project


Usage

Using TombstoneHelper is dead simple. All you have to do is add a using statement and override your page's OnNavigatingFrom and OnNavigatingTo -methods

using TombstoneHelper;
 
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
// Save the state
this.SaveState(e);
}
 
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
// Restore the saved state
this.RestoreState();
}

TombstoneHelper saves the contents, checked state and scroll positions of TextBoxes, PasswordBoxes, CheckBoxes, RadioButtons, Sliders, Listboxes and ScrollViewers that you have given a name with the Name-attribute.

I usually create a base class that handles all the saving and then derive all my application pages from that:

Base-class: Handle the save and restore.

namespace Foo.Pages
{
public class FooPageBase : AutoTombstonePage
{
public FooPageBase()
{
}
 
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
this.SaveState(e);
}
 
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
this.RestoreState();
}
}
}

Page's codebehind: Inherit the base-class

namespace Foo.Pages
{
public partial class ListsPage : FooPageBase
{
public ListsPage()
{
InitializeComponent();
}
}
}

Page's XAML:

<local:FooPageBase x:Class="Foo.Pages.ListsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:local="clr-namespace:Foo.Pages"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignWidth="480"
d:DesignHeight="696"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait"
Orientation="Portrait"
shell:SystemTray.IsVisible="True"
DataContext="{Binding ListPage, Source={StaticResource Locator}}">
126 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×