PropertyDescriptor of collection when a collection's item changes

Grids for WPF Forum

Posted 7 years ago by Vince Lombardo
Version: 11.2.0554
Avatar

When properties change, I need to pass the property's PropertyDescriptor to another method.

When properties that are not collections change, I am using the PropertyChanged event to detect the change and then, to get the PropertyDescriptor of the property, I cast the IPropertyDataAccessor to a PropertyDescriptorDataAccessor and then I am able to access its PropertyDescriptor.

When it comes to properties that are collections, I use the PropertyChildAdded and PropertyChildRemoved events and cast the IPropertyDataAccessor to a CollectionPropertyDescriptorDataAccessor.  This gives me access to the PropertyDescriptor of the collection and so, for collections, that covers adding and removing an item to a collection.

But when an item in a collection changes, the only event that I can see to use is the above mentioned PropertyChanged event.  When this fires, the IPropertyDataAccessor corresponds to the item that was changed in the collection.  So I thought I would take the Parent of the IPropertyDataAccessor to find the collection and get its PropertyDescriptor, but I can't seem to do this as it doesn't cast to a PropertyDescriptorDataAccessor.

How, when an item in a collection changes, am I able to get to the property of the collection it is a part of so I can get the PropertyDescriptor of that collection?

Comments (2)

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

Hi Vince,

I believe the Parent will actually be the PropertyGridDataAccessorItem, which is equivalent to a TreeViewItem. This container also implements IPropertyDataAccessor, but just forwards calls to the actual underlying IPropertyDataAccessor. So you would need to cast the Parent to a PropertyGridDataAccessorItem, then cast it's DataContext to an PropertyDescriptorDataAccessor (if possible).


Actipro Software Support

Posted 7 years ago by Vince Lombardo
Avatar

Thanks, I got it to work like I needed.  

That was a big help pointing me to the DataContext.  I had tried casting to a PropertyGridDataAccessorItem before, but then didn't know what to do with that and didn't think to use its DataContext.

The final cast of the DataContext actually turned out to be a CollectionPropertyDescriptorDataAccessor (which makes sense as that is what I casted the IPropertyDataAccessor to in the PropertyChildAdded event).

Thanks again for your help.

Edit:

As I said above, the IPropertyDataAccessor casts directly to a CollectionPropertyDescriptorDataAccessor in the PropertyChildAdded event, but I just found that in the PropertyChildRemoved event, it is similar to the other case where I needed to first cast the IPropertyDataAccessor to a PropertyGridDataAccessorItem and then cast the DataContext of that to a CollectionPropertyDescriptorDataAccessor.

[Modified 7 years ago]

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

Add Comment

Please log in to a validated account to post comments.