Hey Paul, and everyone else,
Thanks for your replies, of course I looked into Magellan as well, if you recall me e-mailing you a month ago, regarding if it's an overkill for an app that doesn't have many screens. There were a few considerations which I had to make when I was deciding with the frameworks + approach: - People on my team aren't comfortable with new frameworks, even though I am, but they don't want to have to learn another framework, although it's very much closely aligned to ASP.NET MVC - It was also difficult to convince them about using MVVM Light, although I can understand the benefits, but from a new comers point of view, it does seem a little convoluted and going in circles just to abstract the logic out of the code behind. I've just chosen to use the simple WPF navigation framework, because the app somewhat felt like it was progressing in step 1, 2, 3, etc, but simultaneously then they opened to saying, oh no sometimes in Step 4 we might want to bring up a screen which was in Step 2, etc etc, or sometimes it's not even necessarily a page but a modal window. So I currently have this design that I'm not sure if it's going to work 100%, but basically: 1) MainWindow which hosts the frame, would register for 2 or 3 messages in the code behind and help navigate, or go back 2) The Application class, will house a mapping in this manner: Dictionary<ViewModels, VMMappings> where ViewModels is an enumeration, and VMMappings contains two properties, both of which are Type, holding the ViewModelType and ViewType. Basically if someone did Messenger.Send<ViewModels>(ViewModels.ScreenA); It will just lookup the mapping's and instantiate the ViewModel and View and wire them up, and then forward it onto the registered message in MainWindow to navigate to. That's pretty much my current design, it works in principal, but I'm not entirely sure if it opens up to a ball of limitations, i.e. if the ViewModel's or View's have any arguments in their constructors. Thanks for everyones input. --Winston On Thu, Nov 4, 2010 at 12:14 AM, Paul Stovell <[email protected]>wrote: > 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:* [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 > > _______________________________________________ > ozwpf mailing list > [email protected] > http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf > >
_______________________________________________ ozwpf mailing list [email protected] http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf
