我的WPF应用程序中有几个PNG图像来制作按钮。这些图像中的每一个都有一个alpha通道层,#FF040606作为一种颜色(我没有设计图像,所以如果我说错了,我就提前抱歉)。
我试图让alpha图层看起来像在photoshop中设计的那样透明。
这是我用来将每个图像设置为静态图像资源的代码:
<BitmapImage x:Key="backplate" UriSource="pack://application:,,,/ToolBox;component/Images/backplate.png"/>
这是我用来生成按钮的代码。如何使PNG图像上的alpha图层透明?我查看过的所有其他文章都不适用于我的情况或者使用其他语言。
<Button Name="BigScreenButton"
Background="Transparent"
Cursor="Hand"
Visibility="Visible" Margin="17.022,20.001,0,0" ToolTip="Launches a windows designed to be blown up and get attention">
<Button.Template>
<ControlTemplate TargetType="Button">
<StackPanel>
<Image Name="bigscreenstatic"
Source="{StaticResource bigscreenstatic}"
Stretch="Fill"
Visibility="Visible" />
<Image Name="bigscreenhovor"
Source="{StaticResource bigscreenhovor}"
Stretch="Fill"
Visibility="Collapsed" />
<Image Name="bigscreendisabled"
Source="{StaticResource bigscreendisabled}"
Stretch="Fill"
Visibility="Collapsed" />
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled"
Value="false">
<Setter TargetName="bigscreendisabled"
Property="Visibility"
Value="Visible" />
<Setter TargetName="bigscreenstatic"
Property="Visibility"
Value="Collapsed" />
</Trigger>
<Trigger Property="IsMouseOver"
Value="true">
<Setter TargetName="bigscreenhovor"
Property="Visibility"
Value="Visible" />
<Setter TargetName="bigscreenstatic"
Property="Visibility"
Value="Collapsed" />
</Trigger>
<Trigger Property="IsPressed"
Value="true">
<Setter TargetName="bigscreendisabled"
Property="Visibility"
Value="Visible" />
<Setter TargetName="bigscreenhovor"
Property="Visibility"
Value="Collapsed" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>