Home > Software design >  How can I add System.Windows.Forms to WPF application when adding via reference/Depenency doesn'
How can I add System.Windows.Forms to WPF application when adding via reference/Depenency doesn'

Time:05-03

Following every guide everywhere:

  • Step 1:

enter image description here

  • Step 2: it works! Huzzah! Except that it doesn't. Instead I get yellow triangles:

enter image description here

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:

enter image description here

CodePudding user response:

Apparently this is due to using .Net Core and Microsoft couldn't anticipate that people would want to use forms in the new normal...

I found this: 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.
  • Related