Best practices for sharing data between pages

I was wondering what is the best way to send variables like "selectedItem" etc. between pages in UWP? Is it a good idea to just create a static global variable class that every page knows?

+8
static windows-phone uwp persistence
source share
2 answers

I am going to summarize Microsoft Best Practice here:

For simple data (e.g. rows):
Use the Frame.Navigate(TypeName, Object) method, where, since the second argument must always be a string (even if it allows objects), the Second argument can then be retrieved from the NavigationEventArgs.Parameter in the Frame.Navigated event handler.

For complex data (nothing but rows):
You can choose one of two options here, depending on the size and complexity of your application:

  • Or control the link to any complex data inside your App class directly
  • Or, keep a link to them in any Manager class that is a member of your App class. (e.g. NavigationDataManager ).
+11
source share

In fact, if you use the MVVM approach, you have all the necessary information in the ModelView classes. If you are not using MVVM, just use the singleton class or even a static global class.

+1
source share

All Articles