views:

897

answers:

3

Hello,

I have a a navigation application developed in Silverlight 4. It has a main page which contains a frame. I load a particualr view in that frame and I know that I can use NavigationService to navigate to other page which would be loaded in the same frame.

But my question is how it can be done using MVVM? To get the frame do I need to pass the reference of the page?

Also, as per my knowledge one view is not aware of any other views. So what is the best way to make them aware of each other? I have heard of Controller and Mediator but how shall I implement them so as to get the Frame of the mainpage?

It would be very helpful if anyone can give me the example or probably sample code for this.

Thanks in advance.

+1  A: 

When I tried this before, I had the VM fire off a Navigate event when I wanted to change the View. The main View with the frame then did the work of calling the navigation service to navigate to the appropriate page. Still, I remember it was not perfect.

It is quite possible that Navigation is not a good fit with MVVM.

Scott Whitlock
A: 

This article by Nikhil seems like a good fit for your question http://www.nikhilk.net/Entry.aspx?id=232.

It talks about using the MVC pattern when dealing with Silverlight navigation. Nikhil also talks about his framework he created to assist in Silverlight development.

Agies
A: 

Your best shot would be binding the Frame's DataContext to your view model. This enables the loaded page (view) to automatically be notified with the DataContext.

We've even improved the Silverlight navigation with numerous powerful features such as multi-level navigation, page-level security, login redirection, visual transitions and bunch of features targeting business SL apps.

If it can be of any help, check out our navigation sample here http://intersoftpt.wordpress.com/2010/06/29/clientui-part-5-the-supercharged-silverlight-navigation/

James