1

Passing Data from Page to Page for Windows Phone 8.1

i found this great article :

http://www.windowsapptutorials.com/windows-phone/how-to-pass-data-between-different-pages-in-windows-phone-application/

and i understood it very well,

there are few question i came after reading this article is :

[1] which method is better, in which scenarios ? [2] what is the benefits of all 3 methods?

vir
  • 55
  • 1
  • 6

2 Answers2

0

Public property in App.xaml.cs and global variables causes namespace pollution and make the application less testable, so I prefer to use QueryString.

On the other hand, sometimes I need to pass complex object or even collections of complex objects and in this case public property in App.xaml.cs is more preferable in my opinion.

ceth
  • 44,198
  • 62
  • 180
  • 289
0

Small hint: Please state if you are using Silverlight or WinRT, as it makes a big difference. I assume you are using Silverlight here.

Like demas already stated: Global variables are almost never a good idea.

Recommendation: Always use queryString and always only pass IDs in the query.

This means, keep your data in some kind of storage and always read it from there on any page. If you want to pass complex objects, put them to your storage, tell the new page the id and on the new page load it from the storage.

  • If your app gets terminated (tombstoned) in the background and is relaunched on your detail-pages, it may always be that your global variables are empty.

  • It also improves your maintainability: All data accessed by a page will be loaded on that pages code/codebehind/viewmodel; You don't have to check other parts of the app to find out where that data comes from.


Further hint:

It helped me a lot, to think of a Silverlight app like a "web app": The pages are individual pages and the viemodels are the database servers. There is no way to pass data between these pages other than the query string.

Kai Brummund
  • 3,538
  • 3
  • 23
  • 33