我在 .NET Framework 的 PropertyGrid 中使用过 OpenFileDialog。它运行良好:
public class FileSelectorTypeEditor : System.Drawing.Design.UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
if (context == null || context.Instance == null)
return base.GetEditStyle(context);
return UITypeEditorEditStyle.Modal;
}
// etc
}
现在在 .NET 9 上的 WinForms 中,我找不到类型System.Drawing.Design.UITypeEditor
。
我做错什么了?
看来您已使用通用的跨平台
Class Library
模板创建了此库。此模板当然不包含 System.Windows.Forms 程序集。
您本可以选择
Windows Forms Class Library
。无论如何,您可以编辑项目的配置文件,并添加到主文件中
<PropertyGroup>
:此时,当您尝试构建解决方案时,您还会收到通知,要包含这些 Windows 桌面程序集,您还需要重新定位框架定义,将其更改为:
因此项目的配置文件将如下所示:
当然,您也可以添加
<UseWPF>true</UseWPF>
,以防该项目需要一些PresentationFramework程序集。该库现在仅适用于 Windows,并且不能适用于其他平台,因为其中包含 Windows 窗体/Windows 演示框架 (WPF) 程序集。
因此,课程将会变成这样(至少与此处发布的部分相关):