Hi, I am using Caliburn Micro and have a login view model which is displayed on startup.
I am using a separate class which handles all of the connection to the server and provides simple call back events to the ViewModel, this is the ITransportClient.
The users enters their credentials, hits login, and the dialog shows the connection process along a number of states (connecting, validating username, downloading configuration). In the background the Login ViewModel will have called
If logged in OK and all steps are completed, the form should then close and the main window ViewModel should open up. If the credentials are incorrect or a problem downloading settings, an error should be displayed and the login form remain.
If connection is lost to the server (indicated via ITransportClient event), then the application should attempt to reconnect a number of times, and if the server remains offline for a configurable period of time then the login window should be displayed
- How would I best handle the switching between the login dialog and the main window as per the above flow?
- How can the login ViewModel close itself, I see
IWindowManager only has
- What is the best way to separate the above out, allowing the login window to be closed external to the Login ViewModel, and for the login window to be displayed when the user logs out the main window? Should this be done in the bootstrap, or should a separate
ViewModel shell be created for this?
Many thanks, additional info below:
public class SimpleInjectorBootstrapper : Caliburn.Micro.Bootstrapper
private Container container;
protected override void Configure()
this.container = new Container();
protected override object GetInstance(Type serviceType, string key)
protected override IEnumerable<object> GetAllInstances(Type serviceType)
protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
var loginViewModel= this.container.GetInstance<ILoginViewModel>();
var windowManager = this.container.GetInstance<IWindowManager>();
My LoginView model is below:
public class LoginViewModel : PropertyChangedBase, ILoginViewModel
private readonly ITransportClient transportClient;
private readonly IWindowManager windowManager;
private string connectionStatus;
public LoginViewModel(ITransportClient transportClient, IWindowManager windowManager)
this.transportClient = transportClient;
this.windowManager = windowManager;
this.transportClient.ConnectionEvent += new TransportConnectionEventHandler(UpdateStatusHandler);
public void Login()
// set from view, to be done via property, implement later
var username = "test";
var password = "test";
var result = this.transportClient.Login(username, password);
// if result is ok, we should close our viewmodel, however we
// cant call IWindowManager.Close(this) as only show methods exist
// perhaps this is better handled elsewhere?
public void UpdateStatusHandler(string status)
this.ConnectionStatus = status;
public string ConnectionStatus
this.connectionStatus = value;
NotifyOfPropertyChange(() => ConnectionStatus);