views:

412

answers:

3

I'd like to "throw away" the current version of a WPF application and move version 2 to a stable MVVM framework. The main concern I'm having is that I don't see much talk about MVVM frameworks and navigation (i.e., NavigationWindows and Frames).

My current app relies heavily on Pages to present views to the user. I would prefer to keep it this way. I'd rather not change everything to UserControls and rely on DataTemplates to switch out the view I need to present.

Are there any MVVM frameworks that:

  • Work well with NavigationWindows and Pages
  • Provide ViewModels adequate access to the navigation process
  • Provide the ability to change navigation in response to security-related events (e.g., redirect to login Page after logout)
+5  A: 

I tried MVVM with Navigation recently and I created a NavigationManager, which was basically a ViewModel and I bound the NavigationWindow or Frame to that. Then I implemented an OnNavigation event on the NavigationManager. Finally, I handled the OnNavigation event on the NavigationWindow and it navigated to the given page (passed in the event).

Each page had a ViewModel that it bound to.

There's no doubt that MVVM works better with DataTemplates though.

Scott Whitlock
Not a bad way to handle it. Does any framework have something similar?
Will
@Will: Sorry, I'm not familiar with many. I wrote my own called SoapBox Core, but haven't used navigation in anything I've used it for.
Scott Whitlock
+6  A: 

It is not a MVVM framework, but Magellan from Paul Stovell is a lightweight MVC framework to build WPF navigation applications.

Works great with other MVVM frameworks:

Eduardo Molteni
Not perfect, but closer than anything I've seen.
Will
+2  A: 

Great question, Will. I've been looking for the same thing.

So many MVVM toolkits avoided them, I started wondering whether there were reasons to avoid NavigationWindow and Page.

My guess is that since most of the MVVM frameworks aim for cross-compatibility with Silverlight. This means that they tend to ignore navigation/page/hyperlink concerns, since most Silverlight apps are hosted in the browser and get navigation behavior "for free".

I've been trying to learn Rob Eisenberg's Caliburn framework, which seems to have classes that parallel NavigationWindow and Page, but the documentation and samples are for v1.1 and the soon-to-be-released 2.0 version looks quite different.

EDIT: I should have investigated @Eduardo's suggestion sooner! I just independently discovered Paul Stovell's Magellan project, which looks like exactly what you need, Will. From the project homepage:

Magellan is a lightweight MVC framework that makes it easy to build WPF navigation applications. The design is drawn deeply from the ASP.NET MVC framework, and it should feel familiar to anyone who has worked with ASP.NET MVC.

I'll be checking it out as well.

dthrasher