Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8931397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:06:28+00:00 2026-06-15T09:06:28+00:00

I am using Caliburn Micro and have a login view model which is displayed

  • 0

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 ITransportClient.Login().

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 again.

  1. How would I best handle the switching between the login dialog and the main window as per the above flow?
  2. How can the login ViewModel close itself, I see IWindowManager only has ShowDialog, ShowPopup and ShowWindow methods?
  3. 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?

My bootstrapper:

public class SimpleInjectorBootstrapper : Caliburn.Micro.Bootstrapper
{
   private Container container;

   protected override void Configure()
   {
       this.container = new Container();
       this.container.Register<IWindowManager, WindowManager>();
       this.container.Register<IEventAggregator, EventAggregator>();
       this.container.Register<IAppViewModel, AppViewModel>();
       this.container.Register<ILoginViewModel, LoginViewModel>();
       this.container.RegisterSingle<ITransportClient, Transport.WCF.TransportClient>();
   }

   protected override object GetInstance(Type serviceType, string key)
   {
       return this.container.GetInstance(serviceType);
   }

   protected override IEnumerable<object> GetAllInstances(Type serviceType)
   {
       return this.container.GetAllInstances(serviceType);
   }

   protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
   {
       base.OnStartup(sender, e);
       var loginViewModel= this.container.GetInstance<ILoginViewModel>();
       var windowManager = this.container.GetInstance<IWindowManager>();
       windowManager.ShowWindow(loginViewModel);
   }
}

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
    {
        get
        {
            return this.connectionStatus;
        }

        set
        {
            this.connectionStatus = value;
            NotifyOfPropertyChange(() => ConnectionStatus);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:06:29+00:00Added an answer on June 15, 2026 at 9:06 am

    CM uses the IWindowManager interface to provide the contract for window management that CM can understand. The implementation itself is a UI specific thing – e.g. Telerik controls vs Microsoft standard controls = different. IWindowManager is implemented in CM as WindowManager and this manager contains a child class called WindowConductor whose job is to handle the events from the Window control itself and pass calls to the window (its the glue between the viewmodel and views container)

    Take a look:

    http://caliburnmicro.codeplex.com/SourceControl/changeset/view/35f41b2f9113#src%2fCaliburn.Micro.Silverlight%2fWindowManager.cs

    This conductor manages the window for you – if you look at the implementation, you can see that it checks for the presence of certain interfaces such as IActivate, IDeactivate and IGuardClose. If you implement these interfaces, your window gains more lifecycle features.

    Inheriting from Screen instead of PropertyChangedBase is one way to get these interface implementations for free, you also get implementation of IViewAware which provides automatic view caching and a useful method for getting a reference to the view

    Once you have inherited from this class or implemented the interfaces, you can then call methods to close the window via the VM (such as TryClose). The WindowConductor will take care of passing the neccessary calls to the window control, you can even prevent the window from closing using the IGuardClose inteface which allows you to cancel the close operation.

    I assume you already have a handle on Actions in CM, since you seem to have a login method on your VM.

    Now this is more of a question in an answer – do you need to go the popup window route? You could just inherit from Conductor<T>.Collections.OneActive and call ActivateItem(yourViewModel) (T can be IScreen). Your login viewmodel will be deactivated automatically when the new item is activated, or you can open a login failed viewmodel or something of that ilk. Whilst this doesn’t use a separate window, the implementation is quite simple, just bind a ContentControl to ActiveItem on your conductor viewmodel

    Have a look here for details (look at the Simple MDI section and surrounding):

    http://caliburnmicro.codeplex.com/wikipage?title=Screens%2c%20Conductors%20and%20Composition&referringTitle=Documentation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Caliburn.Micro. In my View I have a TextBox Binded to double
I am using Caliburn.Micro I have this WPF View that in design time uses
I have a wpf application using Caliburn.Micro. I need to bind a ListBox to
I have a wpf application using caliburn.micro. It has a datagrid and a combobox.
I am using Caliburn Micro for Implementing MVVM in WPF. I have a static
I've been using the Caliburn.Micro framework lately. I have a ShellView and two screens,
I am using Caliburn Micro in my Project and i have many UserControls and
I just started using Caliburn.Micro and I've noticed in all the examples that the
I have been using Caliburn.Micro's binding via convention in Silverlight 5 and am loving
I have an .NET 4.0 application using Caliburn.Micro. I want to create a dynamic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.