Using System.Windows.Forms classes in a .net core

2020-06-07 07:39发布

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?

1条回答
甜甜的少女心
2楼-- · 2020-06-07 08:29

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

<PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWpf>true</UseWpf>
    <UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
查看更多
登录 后发表回答