Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show/Hide properties on the PropertyGrid #51

Closed
nrvllrgrs opened this issue Mar 18, 2016 · 5 comments
Closed

Show/Hide properties on the PropertyGrid #51

nrvllrgrs opened this issue Mar 18, 2016 · 5 comments

Comments

@nrvllrgrs
Copy link

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.

@abeckus
Copy link
Contributor

abeckus commented Mar 22, 2016

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

@nrvllrgrs
Copy link
Author

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

@abeckus
Copy link
Contributor

abeckus commented Mar 23, 2016

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

@nrvllrgrs
Copy link
Author

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.

@abeckus
Copy link
Contributor

abeckus commented Mar 29, 2016

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

@abeckus abeckus closed this as completed Oct 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants