Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text over semi-transparent background

This must be so simple but I can't do it: if I put a textblock in a container and make the container's opacity < 1, the text inherits that opacity, no matter whether I try to override it in the textblock. How can I keep the text 100% opacity while in a semii-transparent container?

<Grid x:Name="LayoutRoot">
    <Border Background="red" Opacity="0.5">
        <TextBlock Text="TextBlok" Opacity="1"/>
    </Border>
</Grid>
like image 682
Graeme Avatar asked Apr 17 '09 13:04

Graeme


People also ask

How do I change the background opacity without affecting text?

The percentage of opacity is calculated as Opacity% = Opacity * 100 To set the opacity only to the background and not the text inside it. It can be set by using the RGBA color values instead of the opacity property because using the opacity property can make the text inside it fully transparent element.

How do you make a half background transparent?

Changing the opacity of the background color only To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.


2 Answers

Will this do the trick?

<Border Background="#80FF0000">
    <TextBlock Text="TextBlok"/>
</Border>

Setting the background to be transparent, not the whole Border element...

like image 108
Arjan Einbu Avatar answered Oct 16 '22 04:10

Arjan Einbu


Just use the a color value in stead of an opacity to make it transparant.

The Color property can be formed out of 4 parameters being :

  1. Transparancy
  2. Red
  3. Green
  4. Blue

All of them ranging from 0-255

A half transparant blue would be : (128,0,0,255) Translated into XAML (Hexidecimal) : #800000FF

This color you can use in any colorbrush.

So else has already an example how to implementate it in your code I just see.

like image 44
Peter Avatar answered Oct 16 '22 03:10

Peter