views:

259

answers:

1

I'm using a PropertyGrid to show custom properties that are exposed through the implementation of ICustomTypeDescriptor.

My objects are setup in a tree structure and values for each property are either set in each object or inherited from parent objects. In the PropertyGrid I want to visually show the user what properties values are set in the selected object, and which are inherited from parent objects.

Right now I am showing every property it two categories. One set shows what the value is set to in the actual object, with a blank field if it not set. The other set shows the property values assigned to the object that are either set in the object, or inherited if not set in the object.

I would like to combine these two groups into one buy showing set properties in regular text, and inherited values in italic text. However, there doesn't seem to be any way to do that through ICustomTypeDescriptor.GetProperties(). And I don't have easy access to the properties of the PropertyGrid since they get created while the program is running.

+2  A: 

You can't do italics - but you can do bold; the bold behaviour is determined by the PropertyDescriptor's ShouldSerializeValue; you can wrap PropertyDescriptors via various System.ComponentModel tricks (ICustomTypeDescriptor, TypeConverter or TypeDescriptionProvider) and provide your own PropertyDescriptor.

Alternatively, there are similar grids with more options, such as by VisualHint - see "Property customization" on that page.

Marc Gravell
So if a PropertyDescriptor returns true for ShouldSerialize() the property will be bold? This isn't the true intent of this method right? If I'm already serializing these objects using DataContractSerializer does messing with this method risk changing the way my objects are serialized as well?
Eric Anastas
That depends... XmlSerializer (but not, AFAIL, DataContractSerializer) recognises the pattern by name, but it doesn't use PropertyDescriptor. If you use runtime descriptors (rather than a public `bool ShouldSerialize*()` then you should be fine. But up to you...
Marc Gravell