简体   繁体   English

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

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

Following every guide everywhere:随处遵循每个指南:

  • Step 1:第1步:

在此处输入图像描述

  • Step 2: it works.第 2 步:有效。 Huzzah: Except that it doesn't. Huzzah:除了它没有。 Instead I get yellow triangles:相反,我得到黄色三角形:

在此处输入图像描述

This project is tiny for now because I only just started.这个项目现在很小,因为我才刚刚开始。 The guides about yellow triangles talk about conflicts which can't be the case here.关于黄色三角形的指南谈论的冲突在这里是不可能的。 I have next to nothing imported or used yet:我几乎没有进口或使用过任何东西:

在此处输入图像描述

Apparently this is due to using.Net Core and Microsoft couldn't anticipate that people would want to use forms in the new normal...显然这是由于使用.Net Core,微软无法预料到人们会想在新常态下使用 forms ...

I found this: How to use System.Windows.Forms in .NET Core class library我发现了这个: How to use System.Windows.Forms in .NET Core class library

This is what worked:这是有效的:

  • Removed reference/dependancy entirely完全删除了引用/依赖
  • Right-click project, Unload右键单击项目,卸载
  • Right-click project, Edit project file右键单击项目,编辑项目文件
  • Add the following:添加以下内容:
    <PropertyGroup>
        <TargetFramework>net6.0-windows</TargetFramework>
        <UseWPF>true</UseWPF>
        <UseWindowsForms>true</UseWindowsForms>
    </PropertyGroup>
  • Reload project file重新加载项目文件
  • Add "using system.windows.forms" to the top.在顶部添加“使用 system.windows.forms”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM