Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No creation of a WPF window in a DLL project?

Tags:

window

wpf

dll

Is there a reason why Visual Studio won't let me create a WPF window in a DLL project?

I "solved" it by creating a window in an Application Project and copying it to my DLL project. I also found that I could just create a UserControl and change the base class to "Window".

But if I had to do it this way, it's maybe because I shouldn't do it...

like image 745
Antoine Jeanrichard Avatar asked Aug 26 '10 08:08

Antoine Jeanrichard


People also ask

How add DLL to WPF?

View>>Solutions Explorer. References are listed there. Ah right click and Add Project Reference this is the right one. In winforms it's just Add Reference.

How do I display a WPF window?

When a Window is created at run-time using the Window object, it is not visible by default. To make it visible, we can use Show or ShowDialog method. Show method of Window class is responsible for displaying a window.

Can WPF applications be built without using XML?

For this first program, you won't use Visual Studio's WPF Application template but will instead use the Console Application template. This will allow you to build a bare-bones WPF program without the distractions of XAML and multiple source files. Window myWin = new Window(); // Create the Window object.

What is the difference between WPF window and WPF page?

Window is the root control that must be used to hold/host other controls (e.g. Button) as container. Page is a control which can be hosted in other container controls like NavigationWindow or Frame. Page control has its own goal to serve like other controls (e.g. Button). Page is to create browser like applications.


2 Answers

Make sure the project type is WPF User Control Library when you create your project.

If it isn't then no sweat, just edit the csproj file and make sure the <ProjectTypeGuids> element under Project/PropertyGroup contain the following GUIDs

<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

Also, make sure you reference PresentationFramework and System.Xaml in your project, or you will not get any WPF in your code.

like image 112
Florian Doyon Avatar answered Sep 27 '22 17:09

Florian Doyon


You can try adding new WPF User Control Item and change that to Window.

Add New Item->WPF->User Control

In XAML:

Change <UserControl> tag as <Window>

In CS:

Change base class from System.Windows.Controls.UserControl to System.Windows.Window.

like image 42
electron Avatar answered Sep 27 '22 17:09

electron