This blogpost is more like a little hint or tip, if you want to develop your application with the MVVM – design pattern. Within Windows Phone 7 apps you can easily navigate through PhoneApplicationPages in the code-behind of your views with the NavigationService – Class.

But what if you handle some logic/calculation within a ViewModel and you want to navigate to another View on the basis of the result, you cannot access the NavigationService in this static context.

The solution for this is very simple! All you have to do is the following:

  • In the appropiate ViewModel, just create a property of type NavigationService, like so

  • using the NavService like you do in code-behind

  • and don`t forget to set the Property in the code-behind of the approriate view, so that the NavService is valid and to avoid a NullReferenceException 🙂 You can do this in the constructor or any other initialization method.

I hope, that this little tip is useful for someone.