黑色背景下带有不透明度的实心画刷

6

我正在执行以下操作来填充一个带有特定透明度的矩形。

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

这个矩形是用户控件的一部分,它位于黑色背景上。问题在于我得到的不透明度是在白色背景上的。如何更改使其像在黑色背景上应用不透明度。

下面是我得到的绿色填充颜色。 enter image description here (即叠加在白色背景上) 我需要的是这样的效果。 enter image description here (即叠加在黑色背景上)

2个回答

4

虽然这个问题很久了,但也许我的回答可以帮到某些人。以下是我在XAML/VB Visual Studio 2017中所做的,效果非常好:

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

1

看看这个是否有效:

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

这不会改变透明度,只是改变颜色。 - seabass2020

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