TtT23
TtT23

Reputation: 7030

How to launch modeless window and enforce a single instance of it in caliburn micro

What is the recommended way of launching a modeless window but enforcing that there is only one instance of the launched window in the application using Caliburn Micro?

Upvotes: 1

Views: 917

Answers (1)

Metro Smurf
Metro Smurf

Reputation: 38335

I'm not sure if this is the approved method; but, this is what I've done in the past to ensure only a single instance of a window was open at one time. Note that there is not any specific method, afaik, with Caliburn to create a modal type window; you need to set up the window yourself.

// Create a reference to the model being used to instantiate the window
// and let the IoC import the model. If you set the PartCreationPolicy
// as Shared for the Export of SomeOtherModel, then no matter where you are
// in the application, you'll always be acting against the same instance.
[Import]
private SomeOtherModel _otherModel;


public void ShowSomeOtherWindow()
{
    // use the caliburn IsActive property to see if the window is active
    if( _otherModel.IsActive )
    {
        // if the window is active; nothing to do.
        return;
    }

    // create some settings for the new window:
    var settings = new Dictionary<string, object>
                   {
                           { "WindowStyle", WindowStyle.None },
                           { "ShowInTaskbar", false },
                   };

    // show the new window with the caliburn IWindowManager:
    _windowManager.ShowWindow( _otherModel, null, settings );
}

Upvotes: 3

Related Questions