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...
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.
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.
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With