应用不透明度到线性渐变刷。

5

我有一个定义如下的LinearGradientBrush。我想在xaml中某处使用它,但我想在这种特定情况下更改不透明度(仅在此实例中,而不是在其他任何地方使用它)。有什么方法可以实现这一点吗?

 <LinearGradientBrush x:Key="BlueBackgroundBrush" EndPoint="0.874,1.197" StartPoint="0.126,-0.197">
    <GradientStop Color="#1954B2" />
    <GradientStop Color="#1954B2" Offset="0.982" />
    <GradientStop Color="#FF84B2D4" Offset="0.304" />
</LinearGradientBrush>
1个回答

8

没事了,我解决了。我从这个问题进行了修改:如何在另一个LinearGradientBrush中使用LinearGradientBrush?

最终的结果为:

<GradientStopCollection  x:Key="BlueBackgroundStops">
    <GradientStop Color="#1954B2" />
    <GradientStop Color="#1954B2" Offset="0.982" />
    <GradientStop Color="#FF84B2D4" Offset="0.304" />
</GradientStopCollection>

并且要使用它:

 <LinearGradientBrush EndPoint="0.874,1.197" StartPoint="0.126,-0.197" 
                             GradientStops="{StaticResource BlueBackgroundStops}"
                             Opacity=".65"/>

1
仅澄清一下,关键是使用ARGB来指定透明颜色的不透明度。在这种情况下,使用Color="#FF84B2D4" - Robin Bennett
在C#中,如何使用LinearGradientBrush类型来实现这个功能?例如,当LinearGradientBrush是从白色到红色的渐变时,我如何同时使用这个渐变和带有一点透明度的相同渐变?我知道Color类型有一个.WithAlpha(float)方法,但渐变类型没有这个方法。 - Al John

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接