Search code examples
wpfxceed

XCeed PropertyGrid: How to set the right title?


I've implemented ICustomTypeDescriptor to provide my custom descriptor to the XCeed Propertygrid.

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

This works fine, except that the PropertyGrid has as Title "MyDescriptor". I've tried implementing 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);
}

But that doesn't work... How do I ensure that the title of my grid is correct?

Edit: So what I need is a dynamic way of generating the Title for the PropertyGrid. I've updated the code samples above to reflect this.


Solution

  • What you see at the top of the PropertyGrid is not the Title, it’s the TypeName along with an empty title. If you want to see a title beside the TypeName, make sure your class contains a “Name” property. Without the “Name” property, an empty string is added as the title.

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