Closing the ShellViewModel

Feb 28, 2011 at 4:43 PM


What is the best practice for closing the ShellViewModel? e.g. from a File/Exit menu option.  My ShellViewModel derives from Conductor<IScreen>.Collection.OneActive.

I have an Exit() method which gets invoked from the File/Exit menu option, I've tried calling the TryClose() method from here, but I get a 'A Parent or default view is required.' exception.

What I want to happen is for the shell to go through each of its conducted items, and first check its CanClose property, and if true, call a Close method on that item, and if all Close invocations return true, then everything closed, so shut down the app.

I could do this manually in the Exit() method, rather than call TryClose(), but it doesn't seem very clean.  I would have thought I could specify a CloseStrategy on the ShellViewModel, and have that run when I call TryClose() from the ShellViewModel?


Feb 28, 2011 at 7:50 PM

I'm a bit confused, since the TryClose() approach should definitely work, even with the automatic child VMs deactivation cycle.
How do you specify the root VM (ShellViewModel) for the application? Bootstrapper has a generic version Bootstrapper<TRootModel> which takes care of binding the VM to its corresponding default view.

Mar 1, 2011 at 5:32 PM

Ok, I've figured it out.  Ahem.  I was overriding the AttachView method in my ShellViewModel, and not invoking the base implementation.  Move along, nothing to see here.

Mar 1, 2011 at 6:13 PM