3

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?

jb_
  • 958
  • 5
  • 13

1 Answers1

3

Just add

app.InitializeComponent();

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

Mykola Bohdiuk
  • 1,307
  • 12
  • 16
  • It works, but its only a work around, because we setup the main window for the application manually (like `App.Run(new MainWindow())` would do). But the App.xaml itself is still not used. You can try this, if you add resources to the App.xaml and use them inside the window. – jb_ Dec 19 '10 at 12:26
  • 1
    Yes, I just edited the post: `app.MainWindow = ...` really was a simple workaround – Mykola Bohdiuk Dec 19 '10 at 12:42
  • `InitializeComponent` loads everything from xaml – Mykola Bohdiuk Dec 19 '10 at 12:44