开发者

SolidColorBrush with Opacity on a Black background

开发者 https://www.devze.com 2023-04-12 04:42 出处:网络
I am doing the following to fill a rectangle with a certain o开发者_如何学编程pacity. SolidColorBrush fillColor = new SolidColorBrush(myColor);

I am doing the following to fill a rectangle with a certain o开发者_如何学编程pacity.

 SolidColorBrush fillColor = new SolidColorBrush(myColor);
 fillColor.Opacity = 0.3;
 rectangle1.Fill = fillColor;

The rectangle is part of a user control that is on a Black background. The problem is that I am getting the opacity on a White background. How to change it as if opacity is applied on the color on a Black background.

The following is the color I get for a green color fill.

SolidColorBrush with Opacity on a Black background

(i.e as overlaid on white background) What I need is something like this.

SolidColorBrush with Opacity on a Black background

(i.e as overlaid on black background)


Question is years old I know but maybe this will help someone. This is what I did in XAML/VB visual studio 2017. This works great:

Private Sub Hyper1_PointerEntered(sender As Object, e As RoutedEventArgs) Handles Hyper1.PointerEntered
    Hyper1.Background = New SolidColorBrush(Colors.Gold)
    Hyper1.Background.Opacity = 0.6
End Sub


See if this works:

myColor.A = 75; // 255 * 0.3 is approx. 75
SolidColorBrush fillColor = new SolidColorBrush(myColor);
rectangle.Fill = fillColor;
0

精彩评论

暂无评论...
验证码 换一张
取 消