Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SolidColorBrush with Opacity on a Black background

I am doing the following to fill a rectangle with a certain opacity.

 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. enter image description here (i.e as overlaid on white background) What I need is something like this. enter image description here (i.e as overlaid on black background)

like image 845
softwarematter Avatar asked Oct 12 '11 05:10

softwarematter


2 Answers

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
like image 185
user7942284 Avatar answered Oct 25 '22 07:10

user7942284


See if this works:

myColor.A = 75; // 255 * 0.3 is approx. 75
SolidColorBrush fillColor = new SolidColorBrush(myColor);
rectangle.Fill = fillColor;
like image 29
K Mehta Avatar answered Oct 25 '22 06:10

K Mehta