Best Practices / Models and Strategies for Windows Phone 7, MVVM, Silverlight, and Navigation

At the time of creating the Windows Phone 7. application, using the MVVM template, with which we struggled to deal with the template or technique in order to centralize the navigation logic that will correspond to the MVVM.

To give an example, each time the application. our web service is calling, we verify that the input token we assigned to the application. had not expired before. We always return the status to the phone from the web service, and one of them can be Enum.AuthenticationExpired.

If we get that, I think, we would warn the user and return to the login screen. (this is one of many examples of status that we could get)

Now, wanting to keep things DRY, such logic seems to have to be in one place. This is my question.

How do I go on to simulate navigation that relies (essentially) on a switch or operators to tell us where to go to the next without repeating this in all views.

Are there any recognized patterns or methods that anyone can recommend?

thanks

+4
source share
2 answers

It looks like you have a “state” (something you included), followed by an action (where you will be moving). There are several ways to handle this. One could create an INavigationService that provides the NavigateTo method (something), where something encapsulates the current state, and the method returns the next state. Perhaps this method will also perform the page exchange itself.

Another way would be to create an IEnumerable that manages pages, which makes sense in promoting the application, but gets a little fuzzy when you try to control the back button.

Using the Inavigate function, you can click and pop pages (enqueue / dequeue), and then go to the top of the stack and do your thing, and then place the page to return.

+3
source

I can’t say about certain templates or methods, but it looks like you could go to the login page and not back when the login token has expired. If you do the same for all statuses, you can encode your state processing logic in one place and call it where necessary.

+2
source

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


All Articles