Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The user will fill out information in page 1, and the data will be seen in the other page listed in a listbox.

Is it advisable to use data binding?

I've been studying/researching about data binding already for about 2 days and still couldn't understand it.

Simple example would really help.

share|improve this question

As you may have understood by now, pages are stateless in wp7, which means that every time you go from one page to another, the state (variables, objects, etc.) of your previous page is lost.

A quick Google search provided me with this great blog article, and this slide show (see page 21 to 23, this is the second solution I list below).

In short, the author describes four solutions to pass data between pages:

  1. Using a Global Variable
  2. Using the Query String
  3. Using PhoneApplicationSerivce States
  4. Using NextPage instance

What should you use? Here is my advice regarding each solution:

  1. Unless the data is something that is shared among all pages of your application, I suggest you forget about the Global Variable solution, it's not very clean. And even then, prefer solution 3.
  2. The Query String solution is appropriate if you want to pass simple data between your pages, such as Strings, arithmetic values, Boolean, etc.
  3. About the PhoneApplicationService State, I never needed to use it personally but it looks cleaner than using a global variable. If you want to share some variable/object among all your pages, this is the way to go.
  4. The NextPage solution is the one you should use if you want to pass complex objects between two pages. It's the solution I used the most because I did not need to pass data to all of my pages.

Regardless of the solution you choose, on the second page that is supposed to display data coming from the first page, you will have no trouble loading the data.

Finally, here is a link to a quick tutorial application where data is passed from page to page.

share|improve this answer

Let's imagine that you have two pages: MainPage.xaml and SecondPage.xaml.

also you have two viewModels MainViewModel.cs and SecondViewModel.cs

if you use some MVVM framework (MVVM light for example ) you can use a ViewModelLocator, or you can write your own.

so, in OnNavigatied event in every page you can run this code:

var viewModel = ViewModelLocator.MainViewModel;
this.DataContext = viewModel;

Also you can do in a xaml. See the example here :

You can inject a data provider to every view model. So, when the user adds data on the MainPage, MainViewModel saves the data to the data provider (wich holds the data in a memory, or saves it to the isolated storage.)

Then, when you navigates to the SecondPage, SecondViewModel gets a data from the dataProvider.

ViewModelLocator should be responcible for Main and Second view models has the same DataProvider instance.

If you need to pass any flag (was the data updated, Id, ect) you can do it by passing it in a Query String. ( )

This variant is good because your app can be thombstoned ( by the OS in any moment. You can handle this situation by sending a signal (executing a command, sending a message) to a current view model. And it will save data to storage. The

share|improve this answer


 PhoneApplicationService.Current.State["tittle"] = QTittle;
            PhoneApplicationService.Current.State["name"] = QUsername;

        NavigationService.Navigate(new Uri("/EditMyDetails.xaml", UriKind.RelativeOrAbsolute));


 var tittle = PhoneApplicationService.Current.State["tittle"];

        var name = PhoneApplicationService.Current.State["name"];
share|improve this answer
Programmers is about conceptual questions and answers are expected to explain things. Throwing code dumps instead of explanation is like copying code from IDE to whiteboard: it may look familiar and even sometimes be understandable, but it feels weird... just weird. Whiteboard doesn't have compiler – gnat Jan 14 at 7:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.