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

New Post: PropertyGrid for objects in linked projects

$
0
0
Hi there,

I've been trying to get a PropertyGrid to allow editing of an object from a library (a game engine) in an application, without specifying anything UI specific in the library project.

I've hit a bit of a brick wall, so I thought I'd ask here and see if this is possible to do at runtime.

So I have an object in my library with an integer property (using a custom attribute so I can find it while looping through the object's properties), an ID :
class Object
{
 [IdAttribute]
 public int ID
 {
  get;
  set;
 }
}
Then in my application I'm adding an ICustomTypeDescriptor to the PropertyGrid at runtime. The custom type descriptor loops through all of the properties of the Object instance it houses (myObject), and creates a custom property descriptor for each one it finds :
public PropertyDescriptorCollection GetProperties( Attribute[] attributes )  
{
 PropertyDescriptorCollection propertyCollection = new PropertyDescriptorCollection(null, false);

 // Get the properties
 if( myObject != null )
 {
    // Add the properties for the object
    PropertyInfo[] propertyInfo = myObject.GetType().GetProperties();
    foreach( PropertyInfo property in propertyInfo )
    {
      if( property.Name == "ID" )
      {
        propertyCollection.Add( new EngineObjectPropertyDescriptor(myObject, property.Name) );
      }
 }

return propertyCollection;
}
For the supplied property, the custom PropertyDescriptor returns a String displayed in the value portion of the PropertyGrid:

Image

Now the issue - I am unable to edit the value of the string at all (despite have an overridden 'set' method in my PropertyDescriptor), I can't click on it to modify the value at all. The type being returned by the PropertyDescriptor for both the Property and the Component is String.

I would also like to be able to set up a custom editor, so that a string is displayed for the IDs value (currently working), but when you click on the string value it launches a new dialogue that allows you to change the value. I've got a stand alone dialogue set up which I can easily modify, but can't figure out how to programmatically trigger it (or even edit the value of the property).

Any suggestions would be greatly appreciated!

Viewing all articles
Browse latest Browse all 4964

Trending Articles