Windows Phone 7 (Mango) Tutorial - 8 - What is Page State?

Sometime you may want to save the values present in your page while switching from one page to another page, sometime you may want to store the values while switching application between foreground and background.


When you are switching from one application to the other, the first app enters into the deactivated mode. At that time you can store the current state of the page and display them back again by retrieving those values from page state once you return to the first app.


In this chapter we will discuss about the page state. This will help you to know the basics about it, very good for a beginner to jump start with it.


Index - Windows Phone 7 (Mango) Tutorial


What is Page State?

As described above, you can store the current state of the page while switching to a different page or application and retrieve it back once you return to the same page. You can do this by using the Page State. You can use the "State" property present in the PhoneApplicationPage class to implement the same behavior.


Let's have a look into the definition of the State property:




Here you can see that, State is a public property of type IDictionary<string, object> present in the PhoneApplicationPage class. As you already know that, PhoneApplicationPage is the root of any page in Windows Phone application, hence you will be able to find this in all the pages. If you want, you can read more about the Page and PhoneApplicationPage class here:

If you look into the property declaration, you will come to know that, it has only Getters, that means, you can get the state but can't reinitiate the property.


As this is a Dictionary object, you can use the normal operations that you do with dictionary like Add, Remove, Clear etc.


Working with Page State

If you want to set any value to the State, you can use the following code snippet:

public void SetPageState(string key, object value)
    State[key] = value;


Similarly, you can use the following code snippet to retrieve the state value:

public object GetPageState(string key)
    return State.ContainsKey(key) ? State[key] : null;


End Note

Hope, this gave you basic idea about Phone Application's Page State. Now you will be able to do the basic operation with the state and play with the code. Tomorrow we will explore it in depth with a sample application. After that, this chapter will be clear to you before you jump start with your actual application.


Till then, Happy Coding. If you have any queries, drop a line here. I will try to address them as early as possible. If you are already in Twitter, follow me @kunal2383.

If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter , Facebook , Google+ and LinkedIn . I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.


  1. You have to remove the key from state once consumed.


  2. Yes, this is just to make sure that you are not using the same key/value every time. BTW, that was just the basic showcase of what we can do with Page State.

    Stay tuned for my tomorrow's post more on Page State.

  3. Thank you for sharing such relevant topic with us. I really love all the great stuff you provide. Thanks again and keep it coming.

  4. I have read most of your blog posts and I would like to tell you how useful they are not only for me but for all of your readers.

  5. Thank you Kunal.

    I have two pages Page1.xaml and Page2.xaml. I navigated to a web page( and then I used NavigationService.NavigateTo() to go to Page2 from Page1.xaml page. But when i return to the browser page using NavigationService.GoBack() or by pressing the back button. I see the Page1.xaml but it is blank(webbrowser control is white screen). How do i save the state of the Webbrowser so as it display the old page when i return from another page within my application ? I don't want to reload page again because there may be a state where user has entered values in html text fields and he goes to home page and comes back, entered information is lost.


  6. Hello Simmy,

    Find out more about PageState, ApplicationState and Tombstoning here: and verify which one suits your requirement.


  7. Page state are the states in which your app single page work starting to stop everything comes in it.SPSS Assignment experts

  8. Thanks for sharing this useful tutorial steps.....
    Assignment Help

  9. This comment has been removed by a blog administrator.

  10. Thank you for sharing such a nice post which is a great tutorial, it is well displayed and unique in its own way. Highly appreciated.
    essay redoing help

  11. Windows Phone 7 features a user interface based on a design system code named and commonly referred to as Metro.Essay writing service blog Essay writings are mainly used in bachelor’s course, while dissertation is normally applied to a doctorate or PhD etc.

  12. I heard that there is a multiple large updates, the last being Windows Phone 7. i ahve seen some articles related to it in Term paper writing service which is quite informative.

  13. Windows 7 is the currently running system. I was in search of affordable dissertation writing services for completing my dissertation works.I felt This post as quite informative. Thanks for sharing.

  14. Great website pixelgun 3d. Keep posting more informative articles and posts like these. Keep sharing your good work.


© 2008-2016 - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top