how to not expand categories

Grids for WPF Forum

Posted 10 years ago by jeff jarrell
Version: 9.1.0503
Avatar
Is there a way to indicate to the PropertyGrid to NOT expand specified categories? I.e. Some are expanded, some are not.

We have lots of properties that takes a lot of time measure\expand on each push into SelectedObject(s) and requires a lot of scrolling in terms of user experience.

Also, does the current release address the issue where the Categories show, then after a delay expand?

thanks,
jeff

Comments (7)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jeff,

You would need to use an implicit Style for the PropertyGridDataAccessorItem, or explicitly set PropertyGrid.ItemContainerStyle/Selector and use a keyed Style. The Style could then do something like this:
<Style x:Key="{x:Type propgrid:PropertyGridDataAccessorItem}"
        TargetType="{x:Type propgrid:PropertyGridDataAccessorItem}">
    <Style.Triggers>
        <Trigger Property="DataAccessorType" Value="Category">
            <Setter Property="IsExpanded"
                    Value="{Binding DisplayName, RelativeSource={x:Static RelativeSource.Self}, Converter={StaticResource MyConverter}}" />
        </Trigger>
    </Style.Triggers>
</Style>
You would then implement MyConverter as an IValueConverter, which would return true for categories that should be expanded. This binding will only be in effect until the user manually expands or collapses the category, as it would override the binding value.

Alternatively, you would simply use a MultiTrigger with an additional condition on DisplayName. But this route is a little less flexible.

Version 9.1.0503 included a fix that corrects the category issue you described.

Hope this helps.


Actipro Software Support

Posted 10 years ago by jeff jarrell
Avatar
I see how the converter would work to set the category IsExpanded. On the other side of this I need to track the 'state' of the category as they expand\collapse. I need a handle to the CategoryAccessor and know when it changes. Then I can combine it with this converter to set the expanded state.

So how would I track the state of the category collapsed\visible?

What I am trying to get to is that when the user selects an object, open and close categories, goto another object, then come back to the first object, I can set the open\closed state of the categories according to the way the user last left it.

Perhaps, this is going down the multibinding way.

Thanks.
jeff
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jeff,

You would need to add handlers for the PropertyGridDataAccessorItem.Expanded and Collapsed events on the associated PropertyGrid. Those handlers could then update the "state" shared with the Converter. A few problems with this are that the state would need to be static (to be accessible from both the PropertyGrid handlers and the IValueConverter) and it could continually grow (you would need logic to know when you can dump the state of a given object).

I don't believe there is a similar event for when a category is made visible, which is one reason why you need to use an IValueConverter.

Hope this helps.


Actipro Software Support

Posted 10 years ago by jeff jarrell
Avatar
How would I get a handle to the PropertyGridDataAccessorItem(s) in order to handle the events?

I am using a custom datafactory and am using an implementation of ICategory. So I never directly create a PropertyGridDataAccessorItem.

Thanks,
jeff
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Jeff,

You can't handle those events from your custom ICategoryDataAccessor, as that's part of the data layer. The PropertyGridDataAccessorItem is used to display the "items", such as categories (and is what has the expanded state).

The Expanded and Collapsed events are routed events that bubble, so you can hook up generic handlers on the PropertyGrid (something like "propgrid:PropertyGridDataAccessorItem.Expanded="OnExpanded"). Then the e.OriginalSource would have the PropertyGridDataAccessorItem that was expanded, and the DataContext would have your ICategoryDataAccessor.

Since you are using a custom ICategoryDataAccessor, you could expose a new property on that object. So if you have MyCategory, you could add an IsExpanded property to it. Then the Style provided earlier would use "{Binding IsExpanded, Mode=TwoWay}" in the Setter. This would basically tie the expanded states together. If you go this route, you don't need to handle the Expanded/Collapsed events since the updated states will be passed to your underlying object. You would still need to track the state some where though.

Alot of this depends on your setup, if you get stuck please put together a small sample project and email it over to our support address.


Actipro Software Support

Posted 10 years ago by jeff jarrell
Avatar
very nice. this gives me something to chew on. I will see what I can do.

Thanks,
jeff
Posted 10 years ago by jeff jarrell
Avatar
Thought I would share the solution. Turned out to be easier than expected. Added the IsExpanded to our ICategoryAccessor and changed the binding to be two-way.

    <Style x:Key="{x:Type actPropGrid:PropertyGridDataAccessorItem}"
        TargetType="{x:Type actPropGrid:PropertyGridDataAccessorItem}">
        <Style.Triggers>
            <Trigger Property="DataAccessorType" Value="Category">
                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
            </Trigger>
        </Style.Triggers>
    </Style>


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

Add Comment

Please log in to a validated account to post comments.