How do you override the opacity of a parent control in WPF?
Posted
by Metro Smurf
on Stack Overflow
See other posts from Stack Overflow
or by Metro Smurf
Published on 2010-04-16T04:17:04Z
Indexed on
2010/04/16
4:23 UTC
Read the original article
Hit count: 765
When you set the opacity on a Grid
in WPF, all the child elements appear to inherit its Opacity
. How can you have a child element not inherit the parent's opacity?
For example, the following parent grid has one child grid in the middle with a background set to red, but the background appears pinkish because of the parent's opacity. I'd like the child grid to have a solid color, non-transparent background:
<Grid x:Name="LayoutRoot">
<Grid Background="Black" Opacity="0.5">
<Grid.RowDefinitions>
<RowDefinition Height="0.333*"/>
<RowDefinition Height="0.333*"/>
<RowDefinition Height="0.333*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.333*"/>
<ColumnDefinition Width="0.333*"/>
<ColumnDefinition Width="0.333*"/>
</Grid.ColumnDefinitions>
<-- how do you make this child grid's background solid red
and not inherit the Opacity/Transparency of the parent grid? -->
<Grid Grid.Column="1" Grid.Row="1" Background="Red"/>
</Grid>
</Grid>
© Stack Overflow or respective owner