I want to implement tomb-stoning in my WP7 app and this app is not based on MVVM Pattern. Can any one refer me any good example of that to implement that. So I can maintain states of my app with some generic class.
1 Answers
Here are a few links that do pretty well explaining it:
This one does a good job explaining the different states that you have to manage, including the difference between suspended and tombstoned. http://lnluis.wordpress.com/2011/09/25/fast-application-switching-in-windows-phone/
Shawn Wildermuth is really good, and shows you in this video how to implement. http://vimeo.com/14311977
Here's a blog post that explains in good detail http://xna-uk.net/blogs/darkgenesis/archive/2010/11/08/there-and-back-again-a-tombstoning-tale-the-return-of-the-application.aspx
And this one is from the Windows Phone Developer Blog: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2010/07/15/understanding-the-windows-phone-application-execution-model-tombstoning-launcher-and-choosers-and-few-more-things-that-are-on-the-way-part-1.aspx
Basically, when you want to tombstone, you need to use the Application_Deactivated event to store your variables in isolated storage, and use the Application_Activated event to retrieve them. With the advent of Mango (last fall), you should put a test in Application_Activated, to see if the app is coming from a suspended state.
if (!e.IsApplicationInstancePreserved)
{
//do stuff to restore from tombstoned
}
EDIT to add another example: Maybe this additional simple example will help you. http://dotnet-redzone.blogspot.com/2010/09/windows-phone-7-scrollbar-position.html
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
// Remember scroll offset
try
{
ScrollViewer viewer = ((VisualTreeHelper.GetChild(listBox, 0) as FrameworkElement).FindName("ScrollViewer") as ScrollViewer);
State["scrollOffset"] = viewer.VerticalOffset;
}
catch { }
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
object offset;
// Return scroll offset
if (State.TryGetValue("scrollOffset", out offset))
listBox.Loaded += delegate
{
try
{
ScrollViewer viewer = ((VisualTreeHelper.GetChild(listBox, 0) as FrameworkElement).FindName("ScrollViewer") as ScrollViewer);
viewer.ScrollToVerticalOffset((double)offset);
}
catch { }
};
}

- 1,861
- 15
- 29
-
I would also recommend Shawn's book: http://www.amazon.com/Essential-Windows-Phone-7-5-Application/dp/0321752139 – Rich Hopkins Jun 22 '12 at 13:01
-
Thanks for such detailed answer. I know the basic idea of tombstoning. In my case, I have PanromaPage and there are lot of stuff on it Like Longlist selecter on one item on Other Item Listbox and On Thir Item there are many Textboxes. So I want to preserve the state of my page or you can say state of my controls. I am confused how to achieve this – Arslan Pervaiz Jun 22 '12 at 13:07
-
You're not giving a whole lot of information. Like if the controls are bound to something, etc. Here is another nicely detailed example - does it help? http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2010/07/14/silverlight-for-windows-phone-7-tombstoning.aspx – Rich Hopkins Jun 22 '12 at 14:52