VS2022中自定义属性编辑器(UITypeEditor)无法正常工作
.NET 6 WinForms自定义属性编辑器设计模式失效问题
我在DemoControls(.NET 6 WinForms控件库项目)中为组件属性创建自定义属性编辑器,代码如下:
public partial class UserControl1 : UserControl { [Editor(typeof(CustomKeyEditor), typeof(UITypeEditor))] public string CustomKey { get; set; } public UserControl1() { InitializeComponent(); } } public class CustomKeyEditor : UITypeEditor { public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { return UITypeEditorEditStyle.Modal; } public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); //... return "12"; } }
将DemoControls项目引用到Demo项目后,把UserControl1添加到Form1中,发现CustomKeyEditor仅在运行时正常,设计模式下完全无法工作。随后按照官方示例实现代码,同样在.NET 6环境下失效,但切换到.NET Framework 4.8后所有代码均正常运行。
附加环境信息
- 操作系统:Windows 11 Pro (21H2)
- Visual Studio版本:Community 2022 17.3.5
- .NET Framework版本:4.8.04161
- 已安装组件:
- ASP.NET和Web工具 17.3.376.3011
- Azure应用服务工具v3.0.0 17.3.376.3011
- C# Tools 4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea
- Common Azure Tools 1.10
- Cookiecutter 17.0.22179.3
- Microsoft JVM Debugger 1.0
- NuGet Package Manager 6.3.0
- Python - Profiling support 17.0.22179.3
- Python with Pylance 17.0.22179.3
- TypeScript Tools 17.0.10701.2001
- Visual Basic Tools 4.3.0-3.22470.13+80a8ce8d5fdb9ceda4101e2acb8e8eb7be4ebcea
- Visual F# Tools 17.1.0-beta.22363.4+1b94f89d4d1f41f20f9be73c76f4b229d4e49078
- Visual Studio IntelliCode 2.2
内容的提问来源于stack exchange,提问作者shranet
相关产品推荐
相关产品推荐

