Using PropertyChildAdding, PropertyChildAdded

Grids for WPF Forum

Posted 9 years ago by jeff jarrell
Avatar
I am looking to add new properties to the propertygrid from a custom editor. the new properties are not necessarily part of a collection that is the current property.

I am using a custom data factory as well as our own implementation of IPropertyDataAccessor. I use SelectedObject, SelectedObjects. I don't want to refresh via SelectedObject,SelectedObjects to see the new properties. It would seem like getting these events going would do the trick.

Questions
1) How do I get this all started? If I set CollectionDisplayMode="EditableInline"
now I get the little plus sign, that gets it going, but it may not be the right visual treatment for the custom editor.
2) When I click the + sign, I get a call to the IPropertyDataAccessor.CanAddChild which I return true.
3) Next it goes to IPropertyDataAccessor.AddChild. If the current property is a collection I would presume add an element to the current item. I would then expect a call to the datafactory. But if it's not a collection, then add child to what?

Considering we are in the "data layer" it wouldn't seem exactly seem right to add it to the IPropertyAccessor, or is it?

Any help appreciated.

Thanks,
jeff

Comments (1)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jeff,

You are definitely on the right track. Technically, the IPropertyDataAccessor is part of the data layer, which is then presented by a PropertyGridDataAccessorItem. So whatever you return from the DataFactory are considered "data items".

1. That is correct, the "inline" (add/remove) buttons will only be displayed if you set CollectionDisplayMode to "EditableInline". The built-in IPropertyDataAccessors only support the inline buttons for collections. But you can definitely leverage them for your own purposes.

These buttons leverage the PropertyGrid.AddPropertyChildCommand and PropertyGrid.RemovePropertyChildCommand, so technically you could add your own buttons using these commands. I'd recommend you check out the default Styles, to see how the buttons are fully initialized.

2. That is correct. CanAddChild will be called on an IPropertyDataAccessor, to which a property should be added. How that is added is up to you. If the IPropertyDataAccessor represents a collection property, then you'd add it to the collection. If you have a generic collection of sub-properties, then you must store that somewhere (and then you'd have to update that).

The CanRemove is called on the IPropertyDataAccessor that should be removed. So again, in the case of a collection entry, you'd simply remove that item (possibly by storing the index and reference to the collection with the IPropertyDataAccessor).

3. Once you update the "collection", whether that be the underlying property or a custom collection that defines sub-properties, you'd have to "refresh" something. As you pointed out you could refresh the entire PropertyGrid. Alternatively, you could "refresh" the IPropertyDataAccessor whose collection changed.

Our CachedPropertyDataAccessorBase has a refresh method, which refreshes a single property (and it's sub-properties). Basically is raises a INotifyPropertyChanged.PropertyChanged event for "Value", "ValueAsString", "Values", and "IsModified".

This would trigger that single property to be passed to the DataFactory to get a new list of sub-properties.

Hope this helps.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 10 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.