Reputation: 115
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>
Upvotes: 0
Views: 5000
Reputation: 57899
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>
Upvotes: 3
Reputation: 35584
Opacity is a property of Groupbox itself, not of its background.
Try
<Style TargetType="GroupBox">
<Setter Property="Background" Value="White"/>
<Setter Property="Opacity" Value="0.5"/>
</Style>
Or you can style the GroupBox at the place where you use it, as in @Jay's answer.
If you'd really like to change only the background opacity, use the following:
<Style TargetType="GroupBox">
<Setter Property="Background" Value="#80ffffff"/>
</Style>
Upvotes: 0
Reputation: 29196
you can set the opacity to whatever you want directly on the color. the first two hex numbers control the "alpha" of the brush. 7F is 50%
<SolidColorBrush x:Key="MyBrush" Color="#7FFFFFFF"/>
so, your style would look like this:
<Style TargetType="GroupBox">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#7FFFFFFF"/>
</Setter.Value>
</Setter>
</Style>
Upvotes: 0