Collapse PropertyGrid groups after loading

9 posts, 1 answers
  1. Denis
    Denis avatar
    16 posts
    Member since:
    Mar 2012

    Posted 19 Dec 2013 Link to this post

    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?
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 19 Dec 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Denis
    Denis avatar
    16 posts
    Member since:
    Mar 2012

    Posted 19 Dec 2013 Link to this post

    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?
  5. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 19 Dec 2013 Link to this post

    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 >>
  6. Denis
    Denis avatar
    16 posts
    Member since:
    Mar 2012

    Posted 19 Dec 2013 Link to this post

    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)));
        }
    }
  7. Dharmavaram
    Dharmavaram avatar
    73 posts
    Member since:
    Jun 2013

    Posted 24 Oct Link to this post

    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.

     

  8. Yoan
    Admin
    Yoan avatar
    1068 posts

    Posted 27 Oct Link to this post

    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!
  9. Dharmavaram
    Dharmavaram avatar
    73 posts
    Member since:
    Jun 2013

    Posted 27 Oct in reply to Yoan Link to this post

    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

  10. Yoan
    Admin
    Yoan avatar
    1068 posts

    Posted 27 Oct Link to this post

    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!
Back to Top
UI for WPF is Visual Studio 2017 Ready