Winforms.NET 9:找不到UityPeeditor

问题描述 投票:0回答:1

在.NET 9上的Winforms中,我找不到类型

System.Drawing.Design.UITypeEditor
我做错了什么?

	
似乎您已经使用通用的跨平台

Class Library

模板创建了此库。 当然,此模板不包括system.windows.forms组装(IES)。 您可能已经选择了

Windows Forms Class Library
winforms propertygrid .net-9.0
1个回答
0
投票
任何人,您可以编辑项目的配置文件,然后添加到主

<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 }
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.