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>
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.
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.
Will this do the trick?
<Border Background="#80FF0000">
<TextBlock Text="TextBlok"/>
</Border>
Setting the background to be transparent, not the whole Border element...
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 :
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With