In Magellan a ViewModel has access to an INavigator service, which it can use
to navigate to other ViewModels or controllers. For example:
private void SaveCommandExecuted()
{
Navigator.Navigate<MyController>(c => c.Save(this));
}
The controller action might be:
public ActionResult Save(MyViewModel vm)
{
// Save data from vm
return Page("ThanksForSaving", new ThanksForSavingViewModel());
}
The latest Magellan release also has the ability to navigate between VM's
without using controllers at all.
I guess it comes as no surprise that my response would be WPF + navigation =
Magellan :) But if you're rolling your own you could look at that approach.
In more composite applications I use a pub/sub eventing system to navigate - it
might be:
events.Publish(new NavigateEvent<TViewModel>(vm => vm.Initialize(x,y),
"Shell-TopLeftRegion"));
The navigation mechanism would subscribe to that event and figure out where to
show the corresponding view.
Paul
From: [email protected] [mailto:[email protected]] On
Behalf Of Winston Pang
Sent: Wednesday, 3 November 2010 6:03 PM
To: ozDotNet; ozWPF
Subject: MVVM in a navigational paradigm
Hey guys,
I'm trying to apply MVVM in the WPF navigation model.
I was just doing some thoughts around it
Apart from the rule that the view model shouldn't know about the view, how
would a particular view spawn another view, and push it to the navigation
service for example? I've been playing around with some ideas of holding a
mapping between the View and ViewModel in a global list in App. Then have App
register against the messenger/mediator to respond to any other view model's
wanting to spawn a new view and navigating it to it. I'm not sure if I'm on the
right track.
Would love to see how some other people have done it on here?
Thanks.
--Winston