当您Grid
在 WPF 中设置 a 的不透明度时,所有子元素似乎都继承了它的Opacity
. 如何让子元素不继承父元素的不透明度?
例如,下面的父网格在中间有一个子网格,背景设置为红色,但由于父网格的不透明度,背景显示为粉红色。我希望子网格具有纯色、非透明背景:
<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>