Friday, September 21, 2012

navigate from login page to usercontrol after login using mvvm

navigate from login page to usercontrol after login using mvvm

I have login page and I have bind login button to command in view model. I want to navigate from this page to other user control which is Home page.

It is possible to do this using binding between view and view model?

Answers & Comments...

Answer: 1

This is a good question. Let us not forget the reason why you use MVVM in the first place. The good thing about MVVM is that you can separate the data that is presented from the presentation code. Hopefully, by doing this, your application is easier to test, and you can slap a different UI on it e.g. WinRT and it will work.

The requirements are:

  1. You show a logon page,
  2. The user types in their credentials,
  3. You navigate to an application page.

However, if you use the NavigationService, then when the user hits the back-button, they will go back to the logon page, which you probably don't want.

In this case, you are better off showing a Popup that overlays the entire application page. Then close the popup when the credentials are verified.

Depending on whether you prefer View-First or ViewModel-First, you'd structure things differently. Here's a ViewModel first approach:

LogonViewModel logon = new LogonViewModel();  logon.LogonSucceeded += () => {       App.DismissViewFor<LogonViewModel>(logon);       AppViewModel appViewModel = new AppViewModel();       App.ShowViewFor<AppViewModel>(appViewModel); }  App.ShowViewFor<LogonViewModel>(logon); 

You can either roll your own framework to implement App.DismissViewFor, App.ShowViewFor or use one like Caliburn.Micro which provides a ViewLocator.

by : Chui Teyhttp://stackoverflow.com/users/34461




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog