Property Editor for virtual properies

Grids for WPF Forum

Posted 8 years ago by Carol
Version: 10.2.0533
Avatar
I have a property grid that is populated with virtual properties using a custom type descriptor and a property descriptor for the virtual properties. For some of the properties, I want to define a property editor. I can't seem to figure out a way to do this. I tried to create an EditorAttribute and add that to the property descriptor, but that is apparently not correct. Any help is welcome.

Comments (3)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Carol,

The GetEditor method on the PropertyDescriptor is used to get the associated editor. The type passed into this method call will be typeof(ActiproSoftware.Windows.Controls.PropertyGrid.Editors.PropertyEditor) and the return value should be a instance of the editor that should be used. This editor should derive from PropertyEditor.

GetEditor looks for the EditorAttribute in the PropertyDescriptor.Attributes collection. This collection is initialized from the AttributeArray property, but this is only done once. So it really depends on how and when you are adding the EditorAttribute to the property descriptor.


Actipro Software Support

Posted 8 years ago by Carol
Avatar
Thank you for the response. I am adding the editor in the GetProperties method of the custom type descriptor. The problem I am seeing that the property that I am adding is not getting assocated with the Editor Attribute.

Here is a code snippet that shows what I'm doing:

public override PropertyDescriptorCollection GetProperties(Attribute[]attributes)
{

var myProps = GetMyDescriptors();

List<PropertyDescriptor> newMyProps = new List<PropertyDescriptor>();
foreach (var j in myProps)
{
if (j.Name == "Unit")
{
PropertyDescriptor desc = TypeDescriptor.CreateProperty(j.ComponentType, j, new Attribute[] { new EditorAttribute(typeof(DialogTextBoxPropertyEditor), typeof(PropertyEditor)) });
newMetadataProps.Add(desc);
}
else
{
newMyProps.Add(j);
}
}

// Merge the default properties with any dynamic properties
var props = base.GetProperties().Cast<PropertyDescriptor>().Union(newMyProps);

I'm not sure this even possible. The problem I am tryin got solve is I am creating some dynamic properties that are added to a property grid. Some of those properties can be edited with a text property editor. Since they are dynamic, I can't associate the editor to the property via the Editor[] syntax.
Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Carol,

Sorry, it's hard to tell what the issue could be without seeing it in action. If you can please put together a small sample project that reproduces your issue and email it over then we can take a closer look. Be sure to remove any executables or change the extension of the zip file to ensure it gets past our email filters.


Actipro Software Support

The latest build of this product (v2018.1 build 0675) was released 14 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.