框架是.net8,程序是类库dll,需要支持wpf和winform。
默认类库程序是不支持wpf和winform的,手动是无法添加引用或nuget所需要的框架。需要通过以下方法:
添加wpf
在项目文件下的 <PropertyGroup>中添加<UseWPF>true</UseWPF>
即可
添加WinForm支持
查找了很多资料,只有参考资料1 实现了winForm的支持,但WPF和WinForm之间的交互支持框架System.Windows.Forms.Integration无法被引用。
后参考资料2实现了System.Windows.Forms.Integration的添加。方法为:
将项目的sdk改为:<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
,即指定为WindowsDesktop程序(非必须操作)
只需在<PropertyGroup>中添加<UseWindowsForms>true</UseWindowsForms>
,这样也不必指定FrameworkReference就可以直接引用了。
使用时,在cs文件中使用using System.Windows.Forms;using System.Windows.Forms.Integration;
时就不会报错了