How to close an other viewModel?

Topics: Questions
Jul 30, 2012 at 10:34 AM

Is there sth. to close an other viewModel/view? At the moment I use MessageMediator for such things, but maybe there is an more elegant method?

Jul 30, 2012 at 3:16 PM

If you have a reference to the viewmodel, then you can simply call SaveAndCloseViewModel or CancelAndCloseViewModel. If you have no reference, the only way is to send a message out.

In what kind of situation do you want to close a view model (in other words, what is your use case)?

Jul 31, 2012 at 8:41 AM

My use case:

Have a Grid with Tasks. The User can finish these tasks. To finish one task a new window popups where the user can enter some information for this.

Because I use SQL Service broker, my program get a message from my db if there are changes in my taks. So it could be the case, one other user finishes the task, when the finish task window is open at another user screen. So I wirite a message "Task already finished..." and want to close this window from my mainViewModel, where the Handler for my "DataChanged" is placed.

Jul 31, 2012 at 9:06 AM

In this case, I would always broadcast a message with "task finished" and the task id (guid?). Then if you are a task and also working on it, you can close yourself.