Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
460
Making several properties originating from different objects appear simultaneously in the PropertyGrid
posted

Is this somehow possible?

My case:

I have a command editor where each line consists of a command with parameters. However, the number and type of these parameters depend on the specifc command instance, therefore there is no predefined class an instance of which I could assign to the PropertyGrid's SelectedObject property. I would like to be able to edit each command along with its parameters as one flat object in the PropertyGrid even though the parameters are collected at runtime from different objects than the command instance itself.

My understanding so far is that I can not do this because I need a class definition for the SelectedObject.

Even if I use a completely custom PropertyGenerator, I can't collect properties from several objects and expose them as one collection to the PropertyGrid to be edited at the same time, is this correct?

If yes, what would be a good way to achieve is? We thought about dynamic class generation at runtime, but if there is a simpler solution, I'd be all for it.

  • 34510
    Verified Answer
    Offline posted

    Hi Tjark,

    The XamPropertyGrid gets all of the properties from the SelectedObject only.  It uses two types of property generation.  The first is reflection.  This just uses reflection to check the SelectedObject to see what properties it has.  The other type is through TypeDescriptors.  TypeDescriptors let you specify exactly what properties are on the object.  With this generation type enabled, the property grid will call TypeDescriptor.GetProperties when the SelectedObject is set.  This is a method that you override so that you can provide your own property list.  You are then responsible for hooking up the property descriptor to the actual property it refers to.  So that might be an option for you.

    Dynamic class generation would also work as you can use the reflection property generation type to discover those properties in your dynamic object.

    You can see more info on property generation here: http://help.infragistics.com/doc/WPF/2014.2/CLR4.0/?page=xamPropertyGrid_Property_Item_Generators.html