Caliburn Launch without App.xaml, but with bootstrapper

感情迁移 提交于 2021-02-19 03:36:21

问题


I have a WinForms project from which I want to open a WPF window from a WPF user control project. But when I create an instance of the WPF window and call Show(), the bootstrapper isn't loaded. In an Windows Application, it's located in the App.xaml, but an user control project doesn't have this. What can I do? Thanks!


回答1:


The only thing accomplished by having the bootstrapper in App.xaml's resources is instantiation of the bootstrapper and keeping a reference so it isn't garbage-collected. You could try making it instantiate like this:

public class SomeClass {
    static Bootstrapper _bs = new Bootstrapper();

    ...
}

That will make sure it's initialized as part of static construction, which happens sometime before you can create an instance of SomeClass. You may have to experiment to see whether that should happen in your UserControl or in your Window.




回答2:


I have a console application which presents a WPF gui that I made with Caliburn.Micro. I present the GUI like this:

        _App = new App();
        _App.Run();

Where App.xaml contains the bootstrapper and the main thread is STA like this:

[STAThread]
static int Main(string[] args)
{ ... }

I know your situation is different but maybe this will give you an idea.



来源:https://stackoverflow.com/questions/5967293/caliburn-launch-without-app-xaml-but-with-bootstrapper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!