开发者

Windows Phone 7, MVVM, Silverlight and navigation best practice / patterns and strategies

Whilst building a Windows Phone 7 app. using the MVVM pattern we've struggled to get to grips with a pattern or technique to centralise navigation logi开发者_如何学Goc that will fit with MVVM.

To give an example, everytime the app. calls our web service we check that the logon token we've assigned the app. earlier hasn't expired. We always return some status to the phone from the web service and one of those might be Enum.AuthenticationExpired.

If we receive that I'd imagine we'd alert the user and navigate back to the login screen. (this is one of many examples of status we might receive)

Now, wanting to keep things DRY, that sort of logic feels like it should be in one place. Therein lies my question.

How should I go about modelling navigation that relies on (essentially) switch or if statements to tell us where to navigate to next without repeating that in every view.

Are there recognised patterns or techniques that someone could recommend?

Thanks


It sounds like you have a "state" (something you would switch on) followed by an action (where you would navigate to). There are a number of ways to handle it. One would be to create an INavigationService that exposes the NavigateTo(something) method, where something encapsulates the current state, and the method returns the next state. Perhaps that method would also perform the page swapping itself.

Another way might be to create an IEnumerable that drives the pages, which would make sense in an application driving forward but gets a little fuzzy when you are trying to manage the back button.

With the INavigate, you can push and pop pages (enqueue/dequeue) and then the login would get pushed to the top of the stack and do its thing, then pop the page to return to.


I can't say about specific patterns or techniques, but it looks like you could navigate forward to the login page, not back, when the logon token has expired. If you do the same for all statuses, you will be able to code your status handling logic in one place and call it wherever needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜