Custom Property Type

Grids for WPF Forum

Posted 11 years ago by Todd Larson
Version: 13.1.0581

Say I have a property called and typed Shape.  Is there a way to load a dropdown or popup list with subclasses like Box, Triangle, Square, etc?  And when selected, will I be able to expand custom properties added to those subclasses?


Comments (1)

Answer - Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Todd,

Yes, that would be possible. The expansion is generally the easy part, as you just need to mark your objects as being expandable. We do this in our samples like so:

public class ChildObject : BaseObject {
   // ...

 But there are other ways to mark it as expandable, if you are not able to modify the class definition.

As for making a set of predefined values, that is also possible. In PropertyGrid terms, those are called "standard values" (Microsoft's term). These are also typicaly defined using a TypeConverter. You would need to:

  1. Create class that dervices from TypeConverter (but really, since you want it expandable, you'd derive from ExpandableObjectConverter).
  2. Override the TypeConverter.GetStandardValues method and return instances of Shape that will be assigned to your property when they are selected.
  3. Override the TypeConverter.GetStandardValuesSupported method and return true.
  4. Optionally override the TypeConverter.GetStandardValuesExclusive method and return true to indicate that only the values returned from #2 are allowed (i.e. the user can't freely input a new value).
  5. Finally, you'd probably want to override the TypeConverter.ConvertTo method where destinationType is typeof(string) and return an appropriate display string. This would allow you to display the Box class using the string "Box". Otherwise, it will use the ToString method on the instances from #2, which you could also override.
I hope this helps.

Actipro Software Support

The latest build of this product (v24.1.2) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.