自定义属性与Visual Studio的属性窗格中的子属性

问题描述:

我一直无法找到关于此的文档,主要是因为我不知道究竟是什么来搜索。但是我已经看到它是如何在某种程度上完成的,所以我能够在Visual Studio的属性窗格中显示一些属性,但是现在我需要在属性窗格中添加一个具有子属性的属性。我现在回到原点 - 不知道要搜索什么,也无法实现它,因为我找不到相关信息。自定义属性与Visual Studio的属性窗格中的子属性

在大多数控件的属性面板中,你会看到这一点:

外观

  • 背景色
  • 前景色
  • 字体
    • 字体家庭
    • 字体大小等等

我已经可以做到这一点:

外观

  • 背景色
  • 前景色
  • 万岁颜色

不过,现在我需要的东西就像默认的Font Pro一样perty(添加属性,但随后有子属性是展开/折叠的,就像这样:

enter image description here

目前,我知道,在属性面板中VS得到一个自定义属性的唯一方法是做这样的事情:

public Boolean isBaeltazorAwesome { get; set; } 

而这将显示属性窗格中的单个属性。但是我需要如下图所示的内容,您可以在其中扩展Font属性并获取更多可编辑的子属性。

这怎么办?

我知道寻找引用/异地资源是“离题”,但如果你知道任何我会感激,如果你可以分享。当我不知道使用什么术语时,我不知道如何搜索某些东西。这是奇怪的还是什么?

你可以尝试定义TypeConverter属性为自定义属性的类型声明:

[TypeConverter(typeof(MyPropertyConverter))] 
public struct MyProperty 
{ 
    ... 
} 

public class MyPropertyConverter : TypeConverter 
{ 
    public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, Object value, Attribute[] attributes) 
    { 
     PropertyDescriptorCollection collection = TypeDescriptor.GetProperties(typeof(MyProperty)); 
     // Reorganize the collection of sub-properties 
     return collection; 
    } 

    // overrides of the methods: CanConvertTo, ConvertTo, CanConvertFrom, ConvertFrom etc 
} 

见例如:Implementing TypeConverter for Windows Forms