Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hide the header in a WPF Expander?

Tags:

c#

wpf

I have a business requirement that when the user clicks a series of checkboxes in a WPF application that it will show panels depending upon what checkboxes they select. I would like to use the expander panel but I am not sure how to hide the header. The user should not be allowed to see it unless they check the checkbox. Does anyone know?

like image 866
Greg Finzer Avatar asked Jan 18 '11 19:01

Greg Finzer


2 Answers

You can do this via making a custom Style for your Expander.

However, it might be easier to just place the controls in a different panel, and set it's visibility to Collapsed in response to the check box state. The main reason to use Expander is specifically to have the header and controls.

like image 133
Reed Copsey Avatar answered Oct 10 '22 17:10

Reed Copsey


While not the ideal approach you could go this route...

    <Expander>
        <Expander.Header>
            <TextBlock Visibility="{Binding IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}, Mode=FindAncestor}, 
                 Converter={StaticResource BoolToVisibilityConverter}}">My Expander</TextBlock>
        </Expander.Header>
    </Expander>

...where BoolToVisibilityConverter is something like...

    public class BoolToVisibilityConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((bool)value)
                return Visibility.Visible;
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if ((Visibility)value == Visibility.Visible)
                return true;
            return false;
        }

        #endregion
    }
like image 37
Aaron McIver Avatar answered Oct 10 '22 18:10

Aaron McIver