Windows Phone 7 : How to Store Data and Pass Data between Pages by Mingfei Yan

This is a walk-through tutorial for demonstrating following functions:

  • Store data on Windows Phone 7 by using Isolated Storage
  • Pass data through parameter between pages
  • Dynamic generate data grid, which contains data and related link button
  • Use XElement, XAttribute as data structure

I will explain related concepts through codes step by step. This application is used as a shopping list. Users will be able to key-in items they want to shop and view the shopping list as well. Add and Open function are implemented and I will leave remove function for you to try out.

Before start, You could download sourcecode here. And Windows Phone 7 developer package could be downloaded here.

1. Click on File ->New-> Project … Let’s name the project: ShoppingList_Demo.

2. Open Solution Explorer on the right side and right-click on References -> Add Reference… Here, select System.Xml. Linq. We will use XElement and XAttribute later, which is inside System.Xml.Linq package.

3. We will create a page for inserting shopping list records, so that we could retrieve records later. Right-Click on ShoppingList_Demo and select Add->New Item… Name the new page as AddItem.xaml.

4. Open AddItem.xaml, in TitlePanel, replace the ApplicationTitle as “My Shopping List” and replace Page Title as “New Item”. Code is showed as below:

[cc]





[/cc]

5. Inside ContentGrid panel, put in code showed as below:

[cc]
















10 Responses to “Windows Phone 7 : How to Store Data and Pass Data between Pages”

  1. Avatar

    theparks

    Thanks, this article is just what i needed!
    I was looking for how to store data into the isolated storage on the phone.

    Thanks again

    Reply
  2. Avatar

    Mytron1987

    I have been trying to store data from Project Nimbus, its real time data…How is it possible to store?Would you pls give me some help?

    Reply
  3. Avatar

    Chiew Vee Tian

    Woohoo, found your post through Google. I see that your Windows Phone 7 app is almost done ya, nice! I must catch up soon 😀

    Reply
  4. Avatar

    Kabhey

    Hi I try to create this application but when i create addItem.xaml file it will give error “Root Element is missing” How I solve this problem

    Reply
    • Avatar

      Mingfeiy

      Don’t remove the RootElement in the Initial XAML file. I posted the source code link at the beginning of the article. You want to download and see whether it works?

      Reply
  5. Avatar

    Guest

    hi! your codes are great! but do you have codes like to store the “button content” into another page once you clicked on the button?

    Reply
    • Avatar

      Mingfeiy

      Could you specify your problem? What do you mean by “button Content”?

      Reply
      • Avatar

        Arpanimage

         If im not wrong do you want to store the button names that are displayed to another page and display them there??

        Reply
  6. Avatar

    Siddharth

    I get a null reference exception when i call XAttributes, even though I have saved that attribute and that attribute is shown while I am debugging.
    Any help would be good.

    Reply

Leave a Reply