Page navigation in Silverlight 4 using MVVM pattern
I have a navigation application developed in Silverlight 4. It has a main page which contains a frame. I load a particular 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?
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.
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.
精彩评论