Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set background opacity and border opacity in XAML?

Tags:

c#

wpf

xaml

I have a TextBox:

<TextBox x:Name="myTextBox"/> 

The TextBox in code behind has two booleans:

 myTextBox.Background.Opacity = 0;  myTextBox.BorderBrush.Opacity = 0; 

Now this is all good and dandy, but how do I set these two properties in XAML?

Btw, setting:

<TextBox x:Name="myTextBox" Background="#00FFFFFF"/> 

Does not effect the Opacity property. I'd like to specifically set that opacity property in XAML.

like image 824
Shai UI Avatar asked Oct 12 '11 16:10

Shai UI


People also ask

What is opacity in XAML?

Opacity in XAML is defined as a double, not an HTML color triplet. http://msdn.microsoft.com/en-us/library/system.windows.uielement.opacity.aspx. You'll want to set it like this: <TextBlock Opacity="0" /> You can also use a brush to set it: <SolidColorBrush Color="#FF295564" Opacity="0.3"/>

What is opacity WPF?

All WPF controls are inherited from UIElement. The Opacity property of UIElement is used to set transparency of a control. The value of Opacity falls between 0.0 and 1.0 where 0.0 is fully transparent and 1.0 is fully opaque.

How do you make a button transparent in WPF?

You can set a control's background transparent by setting the Background property to null, using the following code: <Button Name="Button1" Height="30" Width="300" BorderBrush="Yellow" Background="{x:Null}" />


2 Answers

You want to do something like this:

<TextBlock Text="foo bar">     <TextBlock.Background>         <SolidColorBrush Color="Azure" Opacity="0.5" />     </TextBlock.Background> </TextBlock> 
like image 139
carbin Avatar answered Sep 27 '22 23:09

carbin


Opacity in XAML is defined as a double, not an HTML color triplet.

http://msdn.microsoft.com/en-us/library/system.windows.uielement.opacity.aspx

You'll want to set it like this:

<TextBlock Opacity="0" /> 

You can also use a brush to set it:

<SolidColorBrush Color="#FF295564" Opacity="0.3"/> 

...and then set the background property to your brush.

like image 29
Joshua Tompkins Avatar answered Sep 27 '22 23:09

Joshua Tompkins