Using PropertyGridValueTemplateSelector

Posted 14 days ago by Avatar Darcy Davidson


I am attempting to use the TreeListView control adjacent to a PropertyGrid to display multiselected/collection data in a 'flattened' format.  To this end, I've reused my TypeDescriptorFactory and PropertyModel classes to organize my objects in the way I want, and I have dynamically created TreeListView columns with ContentControls datacontext'ed to IPropertyModels.  I am stuck on how to get my ContentControl to select and use the same editor that would be used in the adjacent property grid.  When I snoop the property grid, I see it is using the PropertyGridValueTemplateSelector.  I can't quite understand its usage based on the documentation, and can find no example.

Any help to move me forward on this would be much appreciated.



Comments (3)

Posted 13 days ago by Actipro Software Support - Cleveland, OH, USA


PropertyGridValueTemplateSelector is a DataTemplateSelector that requires the item to be an IPropertyModel and it returns the appropriate value-editing template for that model.  That being said, it generally has to walk up the property model tree to get the PropertyGrid that created the model and use info from that to make a DataTemplate selection.  The logic used is "Property Editors" documentation topic.

PropertyGrid is itself a TreeListView.  We effectively set the PropertyGridValueTemplateSelector instance to the TreeListViewColumn.CellTemplateSelector for the value column.

Actipro Software Support
Posted 13 days ago by Darcy Davidson


That pretty much matches my understanding.  I cant figure out why PropertyGridValueTemplateSelector.SelectTemplate(IPropertyModel, gridInstance) returns nothing.  I can't see any meaningful difference between my IPropertyModel (produced manually), and the one created by the PropertyGrid.



Posted 11 days ago by Actipro Software Support - Cleveland, OH, USA


We use an internal class as the root of the data model tree, and that class has a pointer to the PropertyGrid.  If you are manually constructing your data model tree, then the PropertyGridValueTemplateSelector wouldn't be able to find the owner PropertyGrid and then couldn't do most of its logic.  Maybe that's what's going on here.

You'd probably have to make your own custom template selector class.  If you'd like our PropertyGridValueTemplateSelector source code to use as a guide for our logic, please write our support address and we can send it to you.  But you'd have to alter it to somehow point it to a PropertyGrid internally.

Actipro Software Support
Information The latest build of this product (2018.1 build 0670) was released 7 days ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.