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?
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With