有一个复杂的属性需要采用自定义的属性窗体来进行编辑,可是死活不生效,查遍了资料还是没有任何结果,MSDN上的代码拷贝过来也不生效,后来自己发现同样的代码Framework是有效的,本人用的是.Net Core 3.1,后来.Net 6.0也试过,依旧无效,不知道是API哪里变了,还是说Attribute的使用变了,望解惑。
这是MSDN上的链接:https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.design.uitypeeditor?view=netcore-3.1
以下是代码
//
internal class Editor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override bool IsDropDownResizable => false;
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService editorService =(IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
Form2 frm = new Form2();
editorService.ShowDialog(frm);
return "";
}
}
//
[Editor(typeof(Editor), typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public testabc test { get; set; } = new testabc();