Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference System.Windows.Forms in .NET Core 3.0 for WPF apps?

I'm migrating my WPF desktop app from .NET Framework to Core 3.0. I was using System.Windows.Forms.FolderBrowserDialog() and I'm now stuck on how to add this reference to the Core project. There is no "System.Windows.Forms" NuGet package available, is there? Is there any alternative way to display the FolderBrowserDialog in Core?

Update

I created the Core project using the default template and then copied and pasted .cs and .xaml files into it. The .csproj file looks like this:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">   <PropertyGroup>     <OutputType>WinExe</OutputType>     <TargetFramework>netcoreapp3.0</TargetFramework>     <UseWPF>true</UseWPF>   </PropertyGroup> 
like image 612
yaugenka Avatar asked Nov 13 '19 20:11

yaugenka


People also ask

How do I reference a Windows form in WPF?

Click on File >> New >> Project menu and select WPF Application from Templates as shown in Figure 1. In Solution Explorer, right click on References node and select Add Reference menu item. On Browse tab, go to "C:\Program Files\Reference Assemblies\Microsoft\Framework\v3. 0" folder and select WindowsFormsIntegration.

Is it possible to use Windows form in WPF application?

You can use the WindowsFormsHost to add single Forms into an WPF application.

How do you reference a Windows Form?

Forms as a reference in your project. Right-click on 'References' , select 'Add Reference' and look under Assemblies in the dialogue. If you created your project as a Windows Forms project, that reference should have been added for you automatically.


1 Answers

You need to add to csproj an additional switch:

<UseWindowsForms>true</UseWindowsForms> 

Add it below UseWpf. Then try rebuild. After this, you should be able to use Forms namespace.

like image 97
Lukasz Szczygielek Avatar answered Oct 26 '22 17:10

Lukasz Szczygielek