I am new to MVVM and learning it with MVVM Light.
I have an application in wpf with a login window. When the user enters correct credentials the login window should close and a new MainWindow should open. The part of the login is already working but how can I open a new window and close the current (login.xaml)?
Also some parameters must be given to this new MainWindow.
Can anyone put me in the correct direction or provide me some info?
since you are using MvvmLight you could use the
Messenger
Class (a helper class within mvvmlight) which is used to send messages (notification + objects) between ViewModels and between ViewModels and Views, in your case when the login succeeded in theLoginViewModel
(probably in the handler of the Submit Button) you need to send a message to theLoginWindow
to close itself and show that other windows :LogInWindow code behind
and for in the
SubmitButonCommand
at the LogInViewModel (for example) send that closing Message:and use the Same approach to send Object between
LoginViewModel
and thatOtherWindowViewModel
with the exception that this time you need to send Objects instead of justNotificationMessage
: in the LoginViwModel:and to receive that object in the
OtherWindowViewModel
: