Silverlight Navigation using Mvvm-light(oobe)+MEF?

2019-06-22 14:11发布

问题:

What is the best approach for navigating between UserControls/Pages(out of browser experience)? I'm fairly new to Silverlight and even newer to the mvvm pattern.

How well does the Navigation Framework Integrate with the MVVM Light Toolkit? A snippet for general application flow control with the two would be great.

The plan was to use the Navigation Framework for general flow or using Jeremy Likeness's approach to region management(http://csharperimage.jeremylikness.com/search/label/regions) and swapping out regions as needed. I've seen a few places mention replacing the Visual Root, but that sounded like a hack to me.

Any advice, snippets, or a nudge in the general direction would be greatly appreciated.

Thank you.

回答1:

You may find the following post useful: SL4 Navigation Template with MVVM Light



回答2:

I had the same problem and found this link (applies to Silverlight too):

Windows Phone 7 — Navigation between pages using MVVM Light Messaging



回答3:

I'm struggling with the same thing, However, I am kinda steered away from the "NavigationService" because allegedly the journal keeps the object reference in memory or something I read somewhere.

I've been trying to utilize a frame in the main window, and using mvvm light to send navigation messages to the window to change the frame.

Edit: I figured it out.

In the main window (code behind, not viewmodel) I added a Messenger.Default.Register(Of NotificationMessage(Of NavMsg))...

Then in ANY view model I do a Messenger.Default.Send(Of Notificationmessage(Of NavMsg))...

And then I created a NavMsg class which accepts a string uri or an object to navigate to.

Here's some T4 code templates to generate you the code for your view/viewmodel to work with mvvmlight and it demonstrated the closing window message above. http://dl.activeaspsoftware.net/dl.aspx?f=MvvmLightCodeTemplates.zip