How to create a grid with a translucent background, but with solid children?

I have something like this:

<Grid Background="Black" Opacitiy="0.5">
  <Grid.RowDefinitions>...</Grid.RowDefinitions>
  <Image Source="..." Opacity="1.0" Grid.Row="0"/>
  <TextBlock Text="..." Opacitiy="1.0" Grid.Row="1"/>
</Grid>

Unfortunately, the image and text are obtained with 50% opacity. I want a translucent black background with 100% solid image and text children.

What is the best way to do this?

+3
source share
2 answers

Add Rectangleas the first child of the grid, making sure that it covers all the rows and columns of the grid with the desired transparency level:

<Grid>
  <Grid.RowDefinitions>...</Grid.RowDefinitions>

  <Rectangle Fill="Black" Opacity="0.5" Grid.RowSpan="2" />

  <Image Source="..." Grid.Row="0"/>
  <TextBlock Text="..." Grid.Row="1"/>
</Grid>

(I removed the attribute Opacityfrom Imageand TextBlocksince it is not needed here.)

+9
source

Or without the need for an additional user interface element:

<Grid Background="#80000000" Opacitiy="0.5">
  <Grid.RowDefinitions>...</Grid.RowDefinitions>
  <Image Source="..." Opacity="1.0" Grid.Row="0"/>
  <TextBlock Text="..." Opacitiy="1.0" Grid.Row="1"/>
</Grid>

, "# 80000000" Alpha () = "80", = "00" , = "00" , = "00"

+2

Source: https://habr.com/ru/post/1796411/


All Articles