I have a set of custom PropertyDescriptor that I want to add categories too so they display in a more organized fashion in a PropertyGrid. I want each type of PropertyDescriptor to go into a specific Category.
I've tried using TypeDescriptor.AddAttributes() to add attributes to an existing PropertyDescriptor, but the category attribute is not added.
CategoryAttribute intrinsicPropertyCategory = new CategoryAttribute("Intrinsic Properties");
currentDescriptor = new IntrinsicPropertyDescriptor(def);
TypeDescriptor.AddAttributes(currentDescriptor, new Attribute[] { intrinsicPropertyCategory });
I've also tried using TypeDescriptor.AddAttributes() in the constructor for one of my PropertyDescriptors as shown below. But it doesn't work either.
public IntrinsicPropertyDescriptor(IntrinsicPropertyDef propDef): base(propDef.Key, propDef.Attributes)
{
this._type = propDef.Type;
this._key = propDef.Key;
this._readOnly = propDef.ReadOnly;
CategoryAttribute intrinsicPropertyCategory = new CategoryAttribute("Intrinsic Properties");
TypeDescriptor.AddAttributes(this, new Attribute[] { intrinsicPropertyCategory });
}
I'd rather not spend the time going in to detail of why I'm doing what I'm doing. But in the example above IntrinsicPropertyDef is a class that defines a property including a Name, Display Name and Type. So propDef.Attributes includes the DisplayNameAttribute.
An IntrinsicPropertyDef can be displayed with two different custom PropertyDescriptors IntrinsicPropertyDescriptor, and InferedIntrinsicPropertyDescriptor. Every IntrinsicPropertyDescriptor should have a category attribute "Intrinsic Properties", and every InferedIntrinsicPropertyDescriptor should have a category attribute "Inferred Intrinsic Properties".