CategoryModels with manually created PropertyModels in PropertyGrid

Grids for WPF Forum

Posted 5 years ago by Nico - Germany
Version: 19.1.0680
Platform: .NET 4.5
Environment: Windows 7 (64-bit)


I'm having problems with finding the right place to set or change CategoryModels.

In my code, I create PropertyModels and CategoryModels manually to later add them to the PropertyGrid. I tried 2 approaches:

- Add the PropertyModels to the child collection of the CategoryModels. Here I have the problem that I don't know how or where to add the CategoryModels to the PropertyGrid

-  Add the PropertyModels to the PropertyGrid.Properties collection. In this case, I have no idea where to find and change the CategoryModels to fit my needs. My PropertyModels are displayed correctly in the PropertyGrid within their categories, set in the PropertyModel.Category property, but I can't find a way to manipulate the CategoryModel properties.

Is there any convenient way to navigate through the CategoryModels and alter them or get my first approach (adding my CategoryModels to the PropertyGrid) to work?

Thank you in advance!

Comments (3)

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA


All the data model generation is done in the data factory used by the PropertyGrid.  There is a TypeDescriptorFactory instance set to PropertyGrid.DataFactory by default.

The factory's GetDataModels method is the root method called by PropertyGrid.  That will return the list of category or property models at the level requested.  Generally you probably want to get the CategoryModel instances get auto-created from our built-in logic (via looking at PropertyModel.Category).  You could then iterate them in a TypeDescriptorFactory.GetPropertyModels, CategorizeDataModels, or even CreateCategoryModel method override and update things as needed.  The data factory allows you to intercept and alter things at many levels.

What specifically are you trying to change on the categories, just their name?

Actipro Software Support

Posted 5 years ago by Nico - Germany


Thank you for your quick reply!

With my own TypeDescriptorFactory I was able to get the categories in the right order and set the IsExpanded property for each category. For the first level categories the IsExpanded property works as expected (when AreCategoriesAutoExpanded is set to false). Nested categories are always folded, no matter which value IsExpanded has. How can I manage to expand those nested categories which have IsExpanded set to true?

Another question I have refers to changing the background color of the Value Editors: Is it possible to set the background of all Editors (the right column in the property grid..) with one Style based on the property value of my PropertyModel implementation, regardless of the kind of editor?

Thanks again!

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Nico,

Our PropertyGridNestedCategories QuickStart uses AreCategoriesAutoExpanded = true and all nested categories show ok there.  All that property does when set to true is to set the IsExpanded property to true for each ICategoryModel that is created.

If you set AreCategoriesAutoExpanded = false, as long as you set ICategoryModel.IsExpanded to true in method overrides like factory.CreateCategoryModel, they should appear expanded when appropriate.  If you don't think this is working properly, please make a new simple sample project that shows it happening and send that to our support address, mentioning this thread in the e-mail.  Be sure to exclude the bin/obj folders from the ZIP you send and rename the .zip file extension so it doesn't get spam blocked.  Then we'll debug with that to see what's going on.

As for backgrounds, there is a TreeListViewItemCell-targeted Style set by default to PropertyGrid.ValueContainerStyle.  That Style's Template is what has the ContentPresenter for the property value editor and the add/remove buttons for collection items.  If the Style has a Background setter on it, it will use that background for all the value column cells.  That being said, a lot of property value editors (like our edit box based ones) don't have transparent backgrounds, and would block the column background.  Thus they would need to have their backgrounds updated as well.

Actipro Software Support

The latest build of this product (v24.1.2) was released 26 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.