screen deactivation problem

Topics: Framework Services, UI Architecture
Jul 6, 2012 at 3:50 PM

I have a shell that is a Conductor<Screen>.Collection.OneActive It has two child screens, a LoginViewModel and a ProjectViewModel. Whenever a user wants to log out, the ProjectViewModel screen should be closed (if there is a project open) and the LoginViewModel should be activated. 

When the user wants to logout , it is the ProjectViewModel that might need to prevent it and show the user a MessageBox asking whether the project should really be closed. The logic currently is in the ProjectViewModel.CanClose() override, because only the ProjectViewModel has all the information needed to show the MessageBox.

Only when the ProjectViewModel is actually closed (i.e. in case there was a MessageBox, the user clicked 'yes'), the user should be logged out and thereafter when I get the notification that the user was acutally logged out, the LoginViewModel should be displayed.

The question now is, how can I be notified when the ProjectViewModel was actually closed? How do I know that it was closed because it of a Logout request so the `ShellViewModel` can logout the current user and activate the LoginViewModel?

Jul 6, 2012 at 4:30 PM

I think the default behavior of OneActive is to activate the Screen that was last active before the one you close. So in case you only have these two then it should automatically go back to the LoginViewModel. This behavior can be overridden in the conductors DetermineNextItemToActivate. I guess the Logout action could be run from the OnDeactivate method in the ProjectViewModel ( I'm not sure if it runs only if CanClose happens properly). There are also some events that happen in the conductor when you close a item and you could handle if you would like.

I'm new to CM so I might not be the best help but you could start looking from these suggestions.