mergeable properties of different subclasses

Grids for WPF Forum

Posted 12 years ago by Martijn van Kleef - FEI
Version: 11.2.0545
Avatar

we have a class X with some properties that is added to the PropertyGrid.SelectedObject. the functionality (and properties) of class X are extended by using the decorator pattern like this:

class X : OurPropertyGridObject
{
   List<Decorator> decorators { get; }
}

class Decorator : OurPropertyGridObject
{
   string SomeProperty { get; set; }
}

class DecoratorA : Decorator
{ }

class DecoratorB : Decorator
{ }

we use a custom TypeDecriptorFactory to produce the properties for the property grid. it gets all the properties of a OurPropertyGridObject, including that of all decorators, and adds them to the properties like this:

        protected override IList<IPropertyDataAccessor> GetProperties(object value, DataFactoryOptions options)
        {
            List<IPropertyDataAccessor> result = new List<IPropertyDataAccessor>();
            ...
            result.Add(new PropertyDescriptorDataAccessor(ourPropertyGridObjectRef, propertyName));
            ...
            return result;
        }

this works, but what we see now is that "SomeProperty" appears in the property grid once for each decorator. we would have liked to have it in the property grid just once, merged for all of those decorators. what we did now is move all properties from the Decorator class to a separate DecoratorY but that creates unwanted dependencies between decorators. is it possible to merge the property on the Decorator class for all deriving classes? how?

[Modified 12 years ago]

Comments (1)

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Martijn,

Assuming a single object has multiple properties of the same name, then there is nothing built in to "merge" them. We do have support for merging like properties across multiple objects. So when using SelectedObjects, you would see one entry for all the common properties across all of the objects passed.

If you have a single object, then you would need to manually merge the properties with the same name. You could use our MergedPropertyDataAccessor to merge all the PropertyDescriptorDataAccessor for the same property.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.