Caliburn.Micro Login Window sample

Last week I noticed a question related to Caliburn.Micro that I was interested in. So I decided to have a go at coding a solution. While I was thinking about it someone posted an answer to the post on While it wasn't a complete solution I had a go coding that and it does work.

But I decided to attempt it how the original author wanted it done. Today I thought about using the IEventAggregator service and the idea of a separate "Conductor" I got from reading Birth and Death of M-V-VM Triads.

So this is how the app basically works:

  • AppBootstrapper does not use the Genetic version of Bootstrapper. It overloads OnStartup
  • OnStartup is used to create a LoginConductor class
  • LoginConductor basically handles events from for IEventAggregator. OnStartup publishes the LoginEvent to get things started
  • The LoginEvent an instance of LoginWindow to be created and shown. This is the part that's not true to the MVVM style but if you have a fixed requirement I don't see any harm in using it. Done right you should be able to replace the real version with a Mock version for unit testing still.
  • When a login event is handled and is valid it uses the WindowsManager of Caliburn.Micro to open the ViewModel based main window
  • The logout and exit buttons both use events change the state of the system.
  • The logout event closes the main window and uses the Login event to open the LoginWindow again

To be honest I don't think this is a perfect solution for the following reasons:

  • I'm currently not totally sure it releases memory efficiently with the events and repeating the logout/login process
  • LoginConductor is probably something that could be done using IConductor or one of the existing base classes
  • I didn't try IConductor yet since most of it is focused around Silverlight and I'm not very familiar with that to fully understand demo's of it
    • Another thing I had thought about is the HelloScreens sample that comes with Caliburn.Micro, Which is Silverlight but someone recently posted about a WPF version of HelloScreens. One issue I felt with the HelloScreens sample is that it adds a lot of extra "Framework" code to the system which doesn't currently have a lot of documentation in the code though the page Screens, Conductors and Composition in the Caliburn.Micro documentation does have quite a bit of detail. I will probably have to read through that page again.

      Even though I don't think its the best solution I've included the source code just in case it's of any use to anyone.

      One of the main issues with this test was that it contains a Window that is not built for MVVM so it required different processing. I think what I will do next is try and work with a the Conductors built into Caliburn.Micro to see what I can manage with a full MVVM application as that is what I will be able to create in the app that I need a login screen for.