I have started a Class library project in Visual Studio 2019 and now wish to add WPF items (Window, user control, custom control) into it, but the 'Add Item' dialog box doesn't list anything under the WPF section.
I have come across this problem in previous versions of VS and managed to get around it by adding the <ProjectTypeGuids>
element into the csproj file with the relevant WPF GUIDs. However, that doesn't appear to work with the new VS2019 stripped down csproj file, or I don't know where to find the correct GUIDs (as I have only tried using those I used before).
Does anyone know the correct process to follow for VS2019?
P.S. I am aware that this question appears to have been answered before (for example No creation of a WPF window in a DLL project), but as far as I can tell, they are all for previous versions of Visual Studio and the suggestions don't work for me.
Short Answer: Yes! Detailed Answer: It is possible to combine Win Forms and WPF in a single application.
Net Core 3.0. This demonstrates that Microsoft still has faith in WPF as a user interface framework, and the company is still willing to invest in it by updating and integrating it with its new offerings.” “Microsoft released WPF, WinForms, and WinUI on the same day it released.NET Core 3.0 Preview 1.
You can use WPF with C++/CLI. It is a . NET API, however, so it requires the . NET Framework.
For .NET Core projects, right-click on the class library project, choose "Edit project file", and copy the following contents into the .csproj
file:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
For .NET 5 projects you would need a bit different content:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
This should give you the ability to add WPF specific items to the project using the menus.
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