WP7 and NavigationService.

May 16, 2010 at 5:59 AM

Got any suggestions to be able to get navigation service instance to the view model?  I was thinking of using Messenger but not sure how to wire it up... I am unfortunately still learning as I go but best way is hands on right?

I thought about overriding the OnNavigateTo() for the page in question ( I know its not pure seperation but when in need).  I don't know how to register the Messenger for the Send (aka incoming messages) to utilize the Uri once I send it.

May 16, 2010 at 4:01 PM

I got it figured out.. The link to your samples for MIX was messed up but did a little digging and got a copy, messenger is pretty cool little pattern once you know what do to with it :)

 

Coordinator
May 16, 2010 at 4:13 PM

Hi,

What links did you have issues with?

 

Cheers,

Laurent

May 18, 2010 at 6:21 PM
it was someone else that posted a link on your blog that was completely wrong for the zip file had dashes not periods... So all is good.
May 20, 2010 at 3:56 AM
Edited May 20, 2010 at 3:56 AM

Thought I would share what I found out today for all to gain access to the Navigation Service in WP7..

So in your viewmodel you can get this usability via creating a variable as such:

PhoneApplicationFrame root = Application.Current.RootVisual as PhoneApplicationFrame;

this actually has to happen in each click event you want to respond to in your viewmodel this is actually quite nice since it gives you access to the Navigate() method of the NavigationService.

root.Navigate(new Uri("/View/YourView.xaml"));

 

This doesn't require any override of the OnNavigateTo() method of the navservice...

 

Morgan

 

Oct 16, 2010 at 10:22 PM

Hi All,

I am considering which approach to use in my WP7 app (no reference to the navigationservice) and there seems to be a lot of different ways of doing it:

  1.             Use messenging - raise message in VM - http://www.markerstudio.com/technical/2010/07/windows-phone-7-navigation-between-pages-using-mvvm-light-messaging/#comment-683
  2.             Raise an event in the VM and subscribe to it
  3.             Use the method like this -  ((PhoneApplicationFrame)App.Current.RootVisual).Navigate(new Uri("/AboutPage.xaml", UriKind.Relative)); - //http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/1eed99c6-d8ff-4739-81b1-b7e46f61e543
  4.             Make a ref in the VM to your V - not cool!
  5.             Other solutions: Interface - http://garfoot.com/blog/2010/09/silverlight-navigation-with-the-mvvm-pattern/
  6.             Other controller - http://blog.clauskonrad.net/2010/09/wp7-navigationservice-support-when.html   or http://www.codebureau.com/blog/2010/07/05/SimpleWPFPageNavigationFromAnMVVMViewModel.aspx

Is Morgan's solution considered "bad practise" for MMVM? It is the simplest and quickest.

Messenging with MVVM Light seems to be considered the best one but I want to KISS.