views:

786

answers:

4

we are designing a xbap application that has complex, user configurable navigation flow that depend on state of the model\user security etc and some other environmental factors.

The application is having a container view that loads user specific controls inside a Frame, i am wondering whats the preferred practice for having the navigation logic, inside a separate controller or in the viewmodel of the container view..

A: 

I would think that hooking up a top level routed event handler for Hyperlink.RequestNavigate and a CommandBinding for NavigationCommands.GoToPage would be a sufficient level of separation. Were you looking for more?

Drew Marsh
well i was wondering more from architecture prespective, not how its possible in wpf api
+1  A: 

The ViewModel sample of the WPF Application Framework (WAF) shows how navigation can be implemented.

The sample implements a wizard workflow which is dependent on the user input.

jbe
+1  A: 

I would put the navigation flow code in a global controller or service of some kind. You probably don't want your views or view models to have such logic because they would pull quite a lot of dependencies to them, especially if your flow is quite complex and customizable. Instead, you want those views and view models to be easily unit-testable, in which case they would defer what happens when they're done to somebody who's in a better position to make the appropriate decision.

Ludovic
A: 

Drew, any chance of getting a bit more explanation on that. I like that solution but I'm learning and don't quite understand how to put it into practice, especially if there is special logic in the viewModel to determine where to navigate next.

Chris Cap