Search code examples
wpfstylesgroupbox

Styling a groupbox in WPF


How can I set the opacity of the background for a groupbox etc.

The code beneath doesn't compile:

<Style TargetType="GroupBox">
    <Setter Property="Background">
        <Setter.Value>
            <SolidColorBrush Opacity="0.5">White</SolidColorBrush>
        </Setter.Value>
    </Setter>
</Style>

Solution

  • Your code isn't compiling not because of the opacity, but because of the value "White". You have to apply this to the brush Color.

    You can use:

    <SolidColorBrush Opacity="0.5" Color="White" />
    

    or

    <SolidColorBrush Opacity="0.5">
        <SolidColorBrush.Color>White</SolidColorBrush.Color>
    </SolidColorBrush>