5

I have a LinearGradientBrush defined as follows. I want to use this somewhere in my xaml but I want to change the opacity in this particular case (only in this instance, not everywhere I use it). Any ideas how to accomplish this?

 <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>
KrisTrip
  • 4,943
  • 12
  • 55
  • 74

1 Answers1

8

Nevermind, I figured it out. I modified from this question: Use a LinearGradientBrush in another LinearGradientBrush?

to end up with:

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

and to use it:

 <LinearGradientBrush EndPoint="0.874,1.197" StartPoint="0.126,-0.197" 
                             GradientStops="{StaticResource BlueBackgroundStops}"
                             Opacity=".65"/>
Community
  • 1
  • 1
KrisTrip
  • 4,943
  • 12
  • 55
  • 74
  • 1
    Just to clarify this, the key is to use ARGB to specify the opacity of the transparent color. `Color="#FF84B2D4"` in this case. – Robin Bennett Dec 14 '18 at 14:07
  • How do you do this in C# using the `LinearGradientBrush` type? For example when `LinearGradientBrush` is a gradient from white to red, how can I both use this gradient **and** the same gradient with a bit of transparency? I know the `Color` type has an `.WithAlpha(float)` method but gradient types don't have that. – Al John Jul 05 '23 at 08:38