This is a migrated thread and some comments may be shown as answers.

Collapse PropertyGrid groups after loading

8 Answers 177 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Denis
Top achievements
Rank 1
Denis asked on 19 Dec 2013, 06:31 AM
Hello, 

I want PropertyGrid to collapse arbitrary groups into it after control is loaded. I read several forums posts, but neither of suggested solutions work well. Actually, I wrote behavior and it did I what I want, but after migrating on new Telerik controls version 2013.3 it cease work properly. 
I've attached link on test project.

Do you have any ideas how to enforce PropertyGrid collapse group properly?

8 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 19 Dec 2013, 08:01 AM
Hi Denis,

You can work with the methods of property grid: 
1. ExpandGroup(key), CollapseGroup(key)
2. ExpandAll()/CollapseAll()

We will also update our documentation so that it describes their usage.


Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Denis
Top achievements
Rank 1
answered on 19 Dec 2013, 08:40 AM
Hello Maya,
As you can see from attached project, I used this method CollapseGroup(), but it simply doesn't collapse group, when PropertyGrid control is loaded. Can you reproduce this incorrect behavior in my project?
0
Accepted
Maya
Telerik team
answered on 19 Dec 2013, 09:28 AM
Hi Denis,

The thing is that groups are not yet created on Loaded event and GroupDefinitions collection is still empty. 
What you can try is to invoke the method a bit later. For example:
void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(()=>
                AssociatedObject.CollapseGroup(GroupName)));
        }


Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Denis
Top achievements
Rank 1
answered on 19 Dec 2013, 11:28 AM
Hi Maya,
Thanks a lot!
This code you suggested works fine with my test project, but doesn't work in my real application. I found out, that it is character properties of Dispatcher working. This is solution that works for my purposes below. May be it will be helpful for someone else.
public class RadPropertyGridCollapseGroupBehavior : Behavior<RadPropertyGrid>
{
    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject.Loaded += AssociatedObject_Loaded;
    }
 
    protected override void OnDetaching()
    {
        AssociatedObject.Loaded -= AssociatedObject_Loaded;
        base.OnDetaching();
    }
 
    public string GroupName { get; set; }
 
    private void AssociatedObject_Loaded(object sender, RoutedEventArgs args)
    {
        // use DataBind priority to enforce Dispatcher invoke method in appropriate time
        Dispatcher.BeginInvoke(DispatcherPriority.DataBind,
               new Action(() => AssociatedObject.CollapseGroup(GroupName)));
    }
}
0
Dharmavaram
Top achievements
Rank 1
answered on 24 Oct 2016, 10:33 AM

Hi,

 I have a propertyGrid and I want to collapse all the groups. I tried dispatcher in the loaded event and it is working fine.But Here I have a tree view when the selected Item of the tree changes Property Grid updates.So I tried in Item changed event the same code suggested by Maya but it is not working.We have to write behavior as suggested and call appropriately or any other solution??

 

Regards,

Nagasree.

 

0
Yoan
Telerik team
answered on 27 Oct 2016, 08:11 AM
Hello Nagasree,

You can try to use PropertyGrid's ItemChanged event. Then you can execute the code for collapsing the group using a Dispatcher with Background priority. This is needed because the groups are not yet created on ItemChanged event and GroupDefinitions collection is still empty. This is why you need to invoke the method a bit later using the DispatcherPriority.

I hope this helps.

Regards,
Yoan
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
Dharmavaram
Top achievements
Rank 1
answered on 27 Oct 2016, 08:16 AM

Hi Yoan,

    I have tried using dispatcher in Itemchanged event of RadPropertyGrid. It is not working as expected.Can you  please check once and confirm?

Regards,

Nagasree

0
Yoan
Telerik team
answered on 27 Oct 2016, 08:32 AM
Hi Nagasree,

It is working at my end. Please check the attached sample project for a reference.

Regards,
Yoan
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
Tags
PropertyGrid
Asked by
Denis
Top achievements
Rank 1
Answers by
Maya
Telerik team
Denis
Top achievements
Rank 1
Dharmavaram
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or