Retain Property w/sub properties expanded/collapsed state

Grids for WPF Forum

Posted 14 years ago by Michael Nugent
Version: 9.1.0505
Avatar
Hi,

We are extending the property grid by inheriting from ActiproSoftware.Windows.Controls.PropertyGrid.PropertyGrid to allow us to keep the expanded/collapsed state of the property grid categories when a user selects different objects. This works fine for actual categories but not so much for properties that have sub-properties.

For instance, we have an Appearance Category that contains a Border property (which itself contains 3 sub-properties). In the overridden PrepareContainerForItemOverride method I can determine which categories I need to stay open from object to object by use of a generic list that I save/remove based on collapsed and expanded events. When I expand the Border property to display the 3 sub-properties, the originalsource (from the Expanded event) is the Border which at that time is of type PropertyGridDataAccessorItem. When in the PrepareContainerForItemOverride method I can work with the list of Categories and set the expanded/collapsed state of each. When I get to the Appearance Category, it contains 11 Accessors of which Border is one. I have tried holding on to the PropertyGridDataAccessorItem I obtained from the expanded event for the Border property and have tried to cast it to a TreeListView (which is successful), and then set the IsExpanded property to true but the Border Property still displays in a collapsed state on a new object selection.

Any ideas or suggestions are appreciated.

Thanks,

Mike

[Modified at 05/25/2010 01:24 PM]

Comments (2)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Michael,

A new PropertyGridDataAccessorItem is going to be created each time you change the selected object, so retaining this instance won't help.

The PropertyGrid.PrepareContainerForItemOverride method will only be called for the top-level items, which in your case is probably the categories. There is also a PropertyGridDataAccessorItem.PrepareContainerForItemOverride method, which is called for it's items. This continues down the "tree" structure.

The only way for you to hook into the latter would be to create a class that derives from PropertyGridDataAccessorItem, and include code like the following in both your PropertyGrid class and your PropertyGridDataAccessorItem class:
protected override DependencyObject GetContainerForItemOverride() {
    return new MyPropertyGridDataAccessorItem ();
}

protected override bool IsItemItsOwnContainerOverride(object item) {
    return (item is MyPropertyGridDataAccessorItem );
}
Then you have to override MyPropertyGridDataAccessorItem.PrepareContainerForItemOverride as well, like you do in your custom PropertyGrid.


Actipro Software Support

Posted 14 years ago by Michael Nugent
Avatar
Thanks, that did the trick (although I still need to clean up my own code a bit :-)
The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.