当通过 reference/Depenency 添加不起作用时,如何将 System.Windows.Forms 添加到 WPF 应用程序?

How can I add System.Windows.Forms to WPF application when adding via reference/Depenency doesn't work?

到处都遵循每个指南:

这个项目目前还很小,因为我才刚刚开始。关于黄色三角形的指南谈论的冲突在这里是不可能的。我几乎没有进口或使用过任何东西:

显然这是因为使用了 .Net Core,Microsoft 没有预料到人们会想要在新常态下使用表单...

我发现了这个:

这是有效的方法:

  • 完全删除reference/dependancy
  • Right-click 项目,卸载
  • Right-click 项目,编辑项目文件
  • 添加以下内容:
    <PropertyGroup>
        <TargetFramework>net6.0-windows</TargetFramework>
        <UseWPF>true</UseWPF>
        <UseWindowsForms>true</UseWindowsForms>
    </PropertyGroup>
  • 重新加载项目文件
  • 在顶部添加“使用 system.windows.forms”。