Re: MVVM in a navigational paradigm
Why aren't you guys using Presenters plus DataTemplates / Views for the overall orchestration? in that Accessing a Presenter to handle the marshaling between View and Model/ViewModel is perfectly righteous - espec if you cheat and use AutoFac? :) As for mapping ViewModels to Views via Resource Dictionary DataTemplate DataType={x:Type ViewModels:TestViewModel} v:TestView / /DataTemplate In using this, you don't care what the View is? you just keep talking to one another via ViewModels only.. what goes inside the View etc is only the VM's business nobody elses? ContentControl, ItemsControl etc automatically resolve the View for you so the whole DataContext thing is pretty much not needed unless you want to see design-time data etc via Expression Blend (but i've learned to wean myself off that and its pretty disciplined). Regards, Scott Barnes http://www.riagenic.com On Fri, Nov 5, 2010 at 12:30 PM, Miguel Madero m...@miguelmadero.com wrote: Strings are fine most of the time, specially for things like menus or links but for most cases I just delegate the decision to the VM of where to navigate to or if we need to navigate at all. On Wed, Nov 3, 2010 at 7:04 PM, Steven Nagy steven.n...@readify.netwrote: I usually keep the view and the view model separate, such that the VM has no knowledge of the view. From the view model I might issue a call to navigate to a name, such as “Home”. The navigation service will be responsible for working out what view / VM to build/resolve from that name, and where to load that view (ie in a region, in the shell, in a popup, etc). The nav service tends to change quite drastically between applications though, and depends if you’re using prism or other presentation style frameworks. Of course if you just roll with Magellan you don’t need to think about all this. J I need to spend more time with it, but it’s not the first item on my to do list… *Steven Nagy *Readify | Senior Consultant, Technical Specialist (Azure), Mentor | MVP Windows Azure M: +61 404 044 513 | E: steven.n...@readify.net | B: azure.snagy.name** [image: Description: Description: sig banner] * * *P** **Please consider your environmental responsibility before printing this e-mail.* *From:* ozwpf-boun...@list.ozwpf.com [mailto:ozwpf-boun...@list.ozwpf.com] *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 ___ ozwpf mailing list oz...@list.ozwpf.com http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf -- Miguel A. Madero Reyes www.miguelmadero.com (blog) m...@miguelmadero.com ___ ozwpf mailing list oz...@list.ozwpf.com http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf
Re: MVVM in a navigational paradigm
On Wed, Nov 3, 2010 at 7:02 PM, Winston Pang winstonp...@gmail.com wrote: 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? A colleague of mine (much smarter than me) implemented a generic workflow system that was when used by several views (Silverlight/Mobile/Web/WPF). Basically, there was just a core workflow API, with was then held by each of the areas, and they would then implement/subclass appropriate items to render the various items (next/previous buttons, rendering of content in the certain type of question/input/whatever). I think this fits into your requirements. But I know I haven't given a lot of real detail. I can't quite remember exactly how it was implemented, and I don't work there anymore, but contact me offlist perhaps and I can tell you what I remember. The point is, a global mapping sounds bad. I think a strict sort of composition-based approach seems nice, with views being based of the core workflow system and rendered in some dynamic fashion. Hope this is reasonably useful. Thanks. --Winston -- silky http://dnoondt.wordpress.com/ Every morning when I wake up, I experience an exquisite joy — the joy of being this signature.
RE: MVVM in a navigational paradigm
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.NavigateMyController(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 NavigateEventTViewModel(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: ozwpf-boun...@list.ozwpf.com [mailto:ozwpf-boun...@list.ozwpf.com] 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
RE: MVVM in a navigational paradigm
Re: mapping views to view models, I like to use a convention to map view models to views (e.g., FooViewModel should expect a .xaml file named FooPage, FooView or FooWindow). So you shouldn't have to store the mapping explicitly. In Magellan with just MVVM it goes something like this: 1. You tell an INavigator that you want to navigate, specifying: o The name of the ViewModel (foo) o Any parameters (customerID=36) 2. The INavigator maps it to a handler 3. The MVVM handler resolves the VM from the IOC container 4. The MVVM handler looks for an Initialize() method on the view mode that takes the navigation parameters - e.g., public void Initialize(int customerId) {...} 5. A view is found for the ViewModel based on the conventions above 6. The view's DataContext is set to the ViewModel The process is different if you're using MVC controllers, but not too different. The VM also implements an IViewAware interface and is notified about view lifetime events (e.g., activated, deactivating (closing) and deactivated). And each step uses interfaces and strategies to make it easy to plug in to, like ASP.NET MVC. Paul From: ozwpf-boun...@list.ozwpf.com [mailto:ozwpf-boun...@list.ozwpf.com] 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