Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

Created Unassigned: Allow PropertyGrid to use attributes from MetadataType [20482]

$
0
0
I propose a change to the PropertyGrid to allow the use of an associated MetadataType class to define attributes such as DisplayName. This is useful when dealing with auto generated partial classes.

The change is minor, but it does add a dependency on System.ComponentModel.DataAnnotations. The full file is attached, but the change is to use AssociatedMetadataTypeTypeDescriptionProvider to retrieve the PropertyDescriptors.

```
protected static List<PropertyDescriptor> GetPropertyDescriptors( object instance )
{
PropertyDescriptorCollection descriptors;

TypeConverter tc = TypeDescriptor.GetConverter( instance );
if( tc == null || !tc.GetPropertiesSupported() )
{
if (instance is ICustomTypeDescriptor)
descriptors = ((ICustomTypeDescriptor)instance).GetProperties();
else
// descriptors = TypeDescriptor.GetProperties( instance.GetType() );
{
AssociatedMetadataTypeTypeDescriptionProvider provider = new AssociatedMetadataTypeTypeDescriptionProvider(instance.GetType());
descriptors = provider.GetTypeDescriptor(instance).GetProperties();
}
}
else
{
descriptors = tc.GetProperties( instance );
}

return ( descriptors != null )
? descriptors.Cast<PropertyDescriptor>().ToList()
: null;
}
```

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>