Invisible expander button

6 posts, 0 answers
  1. Huy Truong The
    Huy Truong The avatar
    32 posts
    Member since:
    Mar 2008

    Posted 03 Jun 2009 Link to this post

    Hello,
    Some cases we do not want to display expander button which is used to collapse/expand. Could I invisible expander button?
    Thank you for your helps
    Huy
  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 03 Jun 2009 Link to this post

    Hi Huy,

    Unfortunately you cannot really hide the button because it also holds the content of the header. You could try though to disable the button. This way the header will be visible but not clickable.

    I have implemented this as an extension method:

    public static class ExpnaderExtensions  
    {  
        public static void DisableButton(this RadExpander target)  
        {  
            var firstChild = VisualTreeHelper.GetChild(target, 0) as FrameworkElement;  
            if (firstChild == null)  
            {  
                return;  
            }  
     
            var button = firstChild.FindName("HeaderButton"as Control;  
            if (button == null)  
            {  
                return;  
            }  
     
            button.IsEnabled = false;  
        }  
     
        public static void EnableButton(this RadExpander target)  
        {  
            var firstChild = VisualTreeHelper.GetChild(target, 0) as FrameworkElement;  
            if (firstChild == null)  
            {  
                return;  
            }  
     
            var button = firstChild.FindName("HeaderButton"as Control;  
            if (button == null)  
            {  
                return;  
            }  
     
            button.IsEnabled = true;  
        }  
    }  
     


    Please note that this relies on the specific template part of the control and the code will not work if the template part name is changed (if you create a custom template for example).

    Hopefully this will work for you,

    Best wishes,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Huy Truong The
    Huy Truong The avatar
    32 posts
    Member since:
    Mar 2008

    Posted 03 Jun 2009 Link to this post

    Hi Miroslav ,
    Thank you for your helps. One more question for the expander. Could I insivible whole header of expander? In this case, expander is just like a panel.
    I am looking for your feedback. Thank you for your helps.
    Best regards,
    Huy

  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 04 Jun 2009 Link to this post

    Hi Huy,

    Yes, you can do this. Again, I suppose that you want to make it visible or invisible at runtime, otherwise you could use a standard panel (ex. Grid) and switch its visibility.

    To hide the header, use the code below, but replace "HeaderButton" with "HeaderElement" and cast to FrameworkElement and not to Control.

    Then you can change the Visibility of the returned object to Collapsed.

    Hopefully this is what you need,

    All the best,
    Miroslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. andrea bellagamba
    andrea  bellagamba avatar
    43 posts
    Member since:
    Jul 2009

    Posted 06 May 2010 Link to this post

    I am trying to do as you suggested to Hide programmatically the Expander Header, but I get an error

    Specified argument was out of the range of valid values.
    Parameter name: childIndex

    on

    var

     

     

    firstChild = VisualTreeHelper.GetChild(target, 0) as FrameworkElement;

     



    Any solution?

    Thanks
  7. Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 06 May 2010 Link to this post

    Hello Andrea,

    Thank you for contacting us.

    The technique demonstrated by Miroslav is still actual. Please try the attached example and let us know how it works at your side.

    Looking forward for your reply.


    Regards,
    Ivan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
DevCraft banner