在.NET 9上的Winforms中,我找不到类型
System.Drawing.Design.UITypeEditor
。我做错了什么?
似乎您已经使用通用的跨平台
Class Library
模板创建了此库。 当然,此模板不包括system.windows.forms组装(IES)。 您可能已经选择了
Windows Forms Class Library
<PropertyGroup>
::
<UseWindowsForms>true</UseWindowsForms>
在这一点上,当您尝试构建解决方案时,您还被通知,要包含这些Windows桌面组件,您还需要重新定义框架定义,将其更改为:
<TargetFramework>net9.0-windows</TargetFramework>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
当然,您也可以添加
<UseWPF>true</UseWPF>
,以防该项目中需要一些呈现框架组件。结果,该类将变成这样的事情(至少与此处发布的部分有关):
using System.ComponentModel;
using System.Drawing.Design;
public class FileSelectorTypeEditor : UITypeEditor {
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext? context) {
if (context == null || context.Instance == null)
return base.GetEditStyle(context);
return UITypeEditorEditStyle.Modal;
}
// etc
}