tags:

views:

32

answers:

1

I want to use WPF windows in future applications instead of Windows forms.

The current setup is as Class Library Project with a public static method. I have added a Windows Form item to the Project. In the public static method I create an instance of the Windows Form Class and use the method ShowDialog.

The reason why I use this setup is that I need my own .net dialog in an other program. This program can only call public static methods i .net.

I have solved the problem by creating a WPF Application Project and added a public Class item to this project. In the public static method i create an instace of the WPF window class and use the method ShowDialog. This works but I would like to create a dll without main-method.

How to show a WPF window from a public static method in a Class Library project (dll)?

+3  A: 

Class library projects don't have the WPF Window template, so you need to create a UserControl and then change the main tag from <UserControl ...> to <Window ...>. Alternatively, you can create the Window in a WPF application project and then copy the MyWindow.xaml* files to your library project. (In that case, you might need to fix the Build Action property of the Window in the property window. Visual Studio seems to mess that up when copying a XAML file into a non-WPF class library.)

Afterwards, you can show it like you would in an application: In your static method, you create an instance of your Window and call ShowDialog.

Heinzi