问题
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