SonyWWS/ATF

Show/Hide properties on the PropertyGrid

Closed this issue · 5 comments

Is there a way to show or hide properties on the PropertyGrid based on the values of other properties? For example, in the DomPropertyEditor, if the Emotion property were set to Happy then the Goals property would display; otherwise, that property would not be drawn.

Yes there is:
Please see the following class in CircuitEditor example for reference.
public class ModuleProperties : CustomTypeDescriptorNodeAdapter, IDynamicTypeDescriptor
Basically you need to subclass CustomTypeDescriptorNodeAdapter and override projected method GetPropertyDescriptors().
you can inspect the object and create list of descriptors using any conditions you like.

Alan

That works perfectly for attributes on the selected DomNode. Any suggestions for if the DomNode is in an EmbeddedCollectionEditor?

It should work fine for child DomNodes too as long as you register CustomTypeDescriptorNodeAdapter for each DomNodeTypes that have dynamic properties.
If this is not case then there is a bug, please let me know so I can fix it in next update.

Alan

I have a CustomTypeDescriptorNodeAdapter for the child DomNode, which it is registered to in SchemaLoader using
Schema.childNodeName.Type.Define(new ExtensionInfo<DynamicChildNodeProperties>())
Updating the child DomNode's properties in an embedded collection does not update its dynamic properties.

Here is a quick suggestion until I can address this issue with next Update.
I haven't setup a use case to reproduce this bug yet.
But tracing the code path it seems the problem is the property descriptors is cached for optimization purpose..
Try to comment out the code that caches the property descriptors and let me know if it is the case.

change GetPropertyDescriptors() method in class PropertyEditingContext
located at ..\Framework\Atf.Gui\Controls\PropertyEditing

// comment out caching
public static PropertyDescriptor[] GetPropertyDescriptors(PropertyEditingContext context)
{
if (context == null || context.m_selection.Length == 0)
return new PropertyDescriptor[0];

        // don't use cach
        //if (context.m_propertyDescriptors != null)
        //    return context.m_propertyDescriptors;

        PropertyDescriptor[] result = context.CreatePropertyDescriptors();

       // don't cache the result.
       // context.m_propertyDescriptors = result;
        return result;
    }

Also comment out
//private PropertyDescriptor[] m_propertyDescriptors;
to avoid compiler warning as error.

Alan