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

Invisible expander button

5 Answers 218 Views
Expander
This is a migrated thread and some comments may be shown as answers.
Huy Truong The
Top achievements
Rank 1
Huy Truong The asked on 03 Jun 2009, 08:25 AM
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

5 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 03 Jun 2009, 12:04 PM
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.
0
Huy Truong The
Top achievements
Rank 1
answered on 04 Jun 2009, 03:02 AM
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

0
Miroslav
Telerik team
answered on 04 Jun 2009, 06:06 AM
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.
0
andrea bellagamba
Top achievements
Rank 1
answered on 06 May 2010, 10:52 AM
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
0
Ivan
Telerik team
answered on 06 May 2010, 04:02 PM
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.
Tags
Expander
Asked by
Huy Truong The
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Huy Truong The
Top achievements
Rank 1
andrea bellagamba
Top achievements
Rank 1
Ivan
Telerik team
Share this question
or