XCeed PropertyGrid:如何设置正确的标题?

XCeed PropertyGrid: How to set the right title?

我已经实现了 ICustomTypeDescriptor 以向 XCeed Propertygrid 提供我的自定义描述符。

public class MyDescriptor : ICustomTypeDescriptor, IDisposable
{
    public MyDescriptor(IMyInterface metadata)
    {
         /* Use object metadata to build the type descriptor */
    }
}

除了 PropertyGrid 的标题 "MyDescriptor" 外,这工作正常。我试过实施 GetAttributes()

public AttributeCollection GetAttributes()
{
    string theRightTitle = metaData.GetTitle(); // Dynamic title, differs depending on metaData object provided in constructor.
    Attribute[] attributes = new Attribute[] {new DescriptionAttribute(theRightTitle) };
    return new AttributeCollection(attributes);
}

但这不起作用...如何确保我的网格标题正确?

Edit: 所以我需要的是一种为 PropertyGrid 生成标题的 dynamic 方法。我已经更新了上面的代码示例以反映这一点。

我用 DisplayName 属性装饰了我的 class 并且工作正常。

[DisplayName("My Custom Title")]
public class MyConfiguration
{ ... }

您在 PropertyGrid 顶部看到的不是标题,而是 TypeName 和一个空标题。如果您想在 TypeName 旁边看到标题,请确保您的 class 包含“名称”属性。如果没有“名称”属性,则会添加一个空字符串作为标题。

public class MyDescriptor : ICustomTypeDescriptor
{
    public string Name
    {
      get
      {
        return "AAA";
      }
    }
    . . .
}

或者您可以使用静态和动态信息的组合,例如:-

[DisplayName("Data")]
public class MyDescriptor : ICustomTypeDescriptor
{
    public string Name
    {
      get
      {
        return " - My Title";
      }
    }
    . . .
}

属性 网格的标题将为 "Data - My Title"