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 t开发者_运维知识库hat opacity property in XAML.
You want to do something like this:
<TextBlock Text="foo bar">
<TextBlock.Background>
<SolidColorBrush Color="Azure" Opacity="0.5" />
</TextBlock.Background>
</TextBlock>
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.
I don't know when or if this was changed in the past, but at least with WPF 4.5 it's perfectly fine to use 8-digit-hex-color-codes:
<Element Background="#19ff0000"/> // background will be red with an alpha of 10%
The first two digits specify the alpha channel, with 00
(0) beeing fully transparent and FF
(255) beeing fully opaque.
If you just want a transparent background in XAML there is a Transparent preset:
<Border Background="Transparent"/>
精彩评论