Should the transition state always load when navigating the page or only when resuming work with the gravestone?

I am reading through Windows Phone 7.5 Unleashed, and there is a lot of code that looks like this (in the code for the page):

bool loaded; protected override void OnNavigatedTo(NavigationEventArgs e) { if (!loaded) { DataContext = new SomePageViewModel(State); loaded = true; } ((SomePageViewModel)DataContext).LoadTransientState(); ... } ... 

The idea is that loaded will be false when resuming work with the gravestone, so we know that we want to rebuild the view model.

My question is: why load the transition state outside the if block? If our memory was not thrown out (i.e. the application was not buried), can we not just use the old view model without reloading our state?

Should the transition state always load when navigating the page or just when resuming work with the gravestone?

+4
source share
1 answer

I am not familiar with the book and with the code, which you thought was difficult to say whether it is right or not. It comes down to what LoadTransientState actually does.

The approach you want to take to handle the tomb is to make sure that (if that makes sense in the application *), the application / page should be in the same state when the user returns to it, as when they leave.

So, if the LoadTransientState is only related to saving information during the tombstone, then it may be advisable to move it inside the if block.
If we are talking about any other form of transient data, then probably not.

Hopefully LoadTransientState will contain some logic to ensure that it does not install (or overwrite) data that already exists (or has been installed) internally and therefore avoids any expected consequences of the unnecessary use caused.

* Some obvious exceptions are real-time data, timers (possibly), real-time information, etc.

+1
source

Source: https://habr.com/ru/post/1411415/


All Articles