[英]How to set background opacity and border opacity in XAML?
I have a TextBox
: 我有一个TextBox
:
<TextBox x:Name="myTextBox"/>
The TextBox
in code behind has two booleans: 后面的代码中的TextBox
有两个布尔值:
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? 现在这一切都很好,但我如何在XAML中设置这两个属性?
Btw, setting: 顺便说一下,设定:
<TextBox x:Name="myTextBox" Background="#00FFFFFF"/>
Does not effect the Opacity
property. 不影响Opacity
属性。 I'd like to specifically set that opacity property in XAML. 我想在XAML中专门设置opacity属性。
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. XAML中的不透明度定义为double,而不是HTML颜色三元组。
http://msdn.microsoft.com/en-us/library/system.windows.uielement.opacity.aspx 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. ...然后将背景属性设置为画笔。
如果您只想在XAML中使用透明背景,则会有一个透明预设:
<Border Background="Transparent"/>
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: 我不知道过去何时或是否改变了,但至少使用WPF 4.5,使用8位十六进制颜色代码是完全正常的:
<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. 前两位数字指定alpha通道, 00
(0)为完全透明, FF
(255)为完全不透明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.