1

启动无模式窗口但强制在使用 Caliburn Micro 的应用程序中只有一个已启动窗口实例的推荐方法是什么?

4

1 回答 1

3

我不确定这是否是批准的方法;但是,这是我过去所做的,以确保一次只打开一个窗口实例。请注意,没有任何特定的方法,afaik,使用 Caliburn 创建模态类型窗口;您需要自己设置窗口。

// 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 );
}
于 2012-10-12T01:01:19.340 回答