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 the LoginViewModel
(probably in the handler of the Submit Button) you need to send a message to the LoginWindow
to close itself and show that other windows :
LogInWindow code behind
public partial class LogInWindow: Window
{
public LogInWindow()
{
InitializeComponent();
Closing += (s, e) => ViewModelLocator.Cleanup();
Messenger.Default.Register<NotificationMessage>(this, (message) =>
{
switch (message.Notification)
{
case "CloseWindow":
Messenger.Default.Send(new NotificationMessage("NewCourse"));
var otherWindow= new OtherWindowView();
otherWindow.Show();
this.Close();
break;
}
}
}
}
and for in the SubmitButonCommand
at the LogInViewModel (for example) send that closing Message:
private RelayCommand _submitButonCommand;
public RelayCommand SubmitButonCommand
{
get
{
return _closeWindowCommand
?? (_closeWindowCommand = new RelayCommand(
() => Messenger.Default.Send(new NotificationMessage("CloseWindow"))));
}
}
and use the Same approach to send Object between LoginViewModel
and that OtherWindowViewModel
with the exception that this time you need to send Objects instead of just NotificationMessage
:
in the LoginViwModel:
Messenger.Default.Send<YourObjectType>(new YourObjectType(), "Message");
and to receive that object in the OtherWindowViewModel
:
Messenger.Default.Register<YourObjectType>(this, "Message", (yourObjectType) =>
//use it
);