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

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


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.