Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using System.Windows.Forms classes in a .net core 3.0 preview9 project

How can we use classes like Screen in a .NET Core 3.0 WPF project? There are documentation pages for .NET Core 3.0 for them, so I assumed it should work.

VS and the compiler tell me that the namespace Forms does not exist in System.Windows, so it feels like the classes are not in the 3.0 sdk.

There is no System.Windows.Forms package on nuget, and the "Add reference" dialog has only a System_Windows_Forms reference to the .net framework available, which sounds horribly wrong:

enter image description here

Am I missing something?

like image 366
Benni Avatar asked Sep 12 '19 13:09

Benni


People also ask

Does .NET core support WinForms?

NET Core and language features. Open source improvements to WPF and WinForms for . NET Core.

Will WinForms be deprecated?

WinForms won't be deprecated until Win32 is ... which could be quite sometime! WPF on the other hand has few direct dependencies on Win32 so could potentially form the basis of a "fresh start" UI layer on a future version of windows.


1 Answers

You should add <UseWindowsForms>true</UseWindowsForms> in your csproj.

<PropertyGroup>     <OutputType>WinExe</OutputType>     <TargetFramework>netcoreapp3.0</TargetFramework>     <UseWpf>true</UseWpf>     <UseWindowsForms>true</UseWindowsForms> </PropertyGroup> 
like image 166
Daniel A. White Avatar answered Oct 04 '22 01:10

Daniel A. White