Blog Post

Message Based Navigation for WP7 MVVM Apps

Download this episode

Download Video

Description

Do you have an MVVM-based Windows Phone 7 application and you don't like having to hook into the RootFrame to navigate between pages?  Do you wish you could just "ask" to navigate to a new view from your view model? One possible solution can be found in this screencast.

Using an message bus to process navigation messages, view models can publish messages that are then handled by a separate navigation service, successfully decoupling your view model from the Windows Phone navigation service. 

Get the finished source code here

Embed

Format

Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image
      Linus K

      That seems like an awful lot of code and xaml spread out.

      I solve this problem by having my VMs depend upon a IMyAppNavigationService that has methods such as
      void NavigateToPersonView(string id);

      That way all the URIs and navigation logic is in one class, the MyAppNavigationService. Even though message buses are cool I don't see the benefit here.

      /Linus

    • User profile image
      JeffBrand

      I like to wire up XAML as much as I can.  I don't think it is all that much code really... the MessageBus and NavigationHandler (which is the same thing as your IMyAppNavigationService) are very small.  I replace the dependency you have on the nav service with a dependency on the message bus, which provides me additional capabilities.  Too each there own... whatever works for the apps you build.  Just thought it was an interesting alternative.

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.