Refresh PropertyGrid lose the SelectedItem

Grids for WPF Forum

Posted 2 years ago by Guillaume Guimond-Croteau
Version: 19.1.0687
Avatar

I have a boolean property that changes the availability of 2 other properties based on the result. These properties need a PropertyGrid.Refresh in order to be seen or hidden, but each time I call the refresh, the SelectedItem is set to the top first item of the grid that is not a category property and I lose all expanded arrows.

Is there a way to keep the SelectedItem and the expanded arrows after the PropertyGrid.Refresh? Am I doing this correctly in the first place?

Thanks!

Comments (6)

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

Hello,

We don't have anything that persists the expansion/scroll state at this time.  Have you seen our PropertyGridDynamicProperties QuickStart?  It shows one way of achieving properties that can show/hide based on something else, and without doing a Refresh call.  This allows state to be retained better.


Actipro Software Support

Posted 2 years ago by Guillaume Guimond-Croteau
Avatar

I just saw that this example is not categorized. By making is categorized and setting the Orientation to its own category, I now have an empty category when Orientation is hidden. Is there a way to also hide the category when all its childs are not visible? 

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

Hiding categories isn't in the sample, but I'd think you could use a similar concept where:

  • In the PropertyGrid XAML, you would set CategoryStyle to a Style that targets grids:PropertyGridItem, which is the "row" in the property grid.  And have a similar Visibility Setter.
  • Make a CustomCategoryModel class that inherits CategoryModel.
    • Add a nullable isVisible field like in CustomPropertyModel.
    • Add an InvalidateIsVisible method like in CustomPropertyModel.
    • Add an IsVisible property that if the isVisible field is null, will loop through Children and examine each one.  If each child is a CustomPropertyModel and has IsVisible=false, then you know there are no children so update the isVisible field to false.  Otherwise, make it true.
  • In CustomDataFactory, override CreateCategoryModel to make an instance of CustomCategoryModel.
  • In CustomPropertyModel.InvalidateIsVisible, look at its Parent and if it's a CustomCategoryModel, call the parent's InvalidateIsVisible method.

The idea is that category models can then indicate their visibility based on at least one child being visible.  I hope that helps get you going!


Actipro Software Support

Posted 2 years ago by Guillaume Guimond-Croteau
Avatar

The base style was lost while defining the CategoryStyle, is there a way to use the base style and add the Visibility setter to it? I would like to keep the default category actipro look

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

Unfortunately you'd have to clone our PropertyGridCategoryItemContainerStyle from the default Styles, and base it on that.  If you have a WPF Studio license, then the default Styles and templates will be downloadable from the organization account page, right where the license is obtained.

This brings up a good pain point though for extending category styles.  We will add a ComponentResource key for the next version so that you'll be able to reference our default style externally to base yours on it, using this:

{StaticResource {x:Static themes:GridsResourceKeys.CategoryPropertyGridItemStyle}}


Actipro Software Support

Posted 2 years ago by Guillaume Guimond-Croteau
Avatar

Great, I solved my issues thanks to your answers. Thank you!

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

Add Comment

Please log in to a validated account to post comments.