WPF App.xaml in different Assembly

时光总嘲笑我的痴心妄想 提交于 2019-12-12 15:01:20

问题


I want to setup a WPF Application. But instead of using the entry point of the application to a App.xaml itself, I've to projects.

The first projects is a Windows Application and has a normale Main function. And I've an additional project (WPF control library), that has the App.xaml, windows, controls and all it needs.

The main method start the Application like this:

[STAThread]
static void Main()
{
     Application.Run();
}

Where Application is a class in the library:

public static class Application
{
      public void Run()
      {
            App app = new App();
            app.Run();
      }
}

Where app is my App.xaml. App.xaml defines a startup uri MainWindow.xaml. But if I run the application, the window is never displayed, but the application itself runs.

I can not setup the App.xaml in the first assembly, because I've to support multiple window frameworks (WPF, Gtk#, etc). Any suggestions how to manage this scenario?


回答1:


Just add

app.InitializeComponent();

between App app = new App(); and app.Run();.



来源:https://stackoverflow.com/questions/4482747/wpf-app-xaml-in-different-assembly

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