我想在silverlight按钮上使用透明的png文件。另外我希望按钮本身是透明的,因此背景(按钮后面)显示出来。我发现如果我设置按钮的不透明度,它也会影响图像。我不希望整个图像是透明的 - 只是PNG中定义的透明部分。
关于如何实现这一目标的任何想法?
答案 0 :(得分:3)
Silverlight支持png透明度。这有效:
<UserControl x:Class="SilverlightApplication17.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="Green">
<Button Width="200" Height="200">
<Button.Content>
<Image Source="http://wildermuth.com/images/tx_head.png" />
</Button.Content>
</Button>
您应该会看到图像对按钮背面是透明的。如果你想让按钮透明,那么你需要创建一个清晰的按钮模板。 texmex5答案中的链接是下降的。
答案 1 :(得分:1)
从我后来的调查来看,似乎并非所有透明的PNG都能奏效。它们必须是基于alpha的透明度(而不是基于调色板)。它们还必须至少是16位图像。标准的8位不起作用。
答案 2 :(得分:0)
<UserControl x:Class="MyProject.SilverlightControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="Green">
<Image Width="18" Height="18" DataContext="{Binding PrintMovementCommand}" Source="{Binding IconSource}" VerticalAlignment="Center" HorizontalAlignment="Center" ToolTipService.ToolTip="{Binding Title}" Cursor="Hand">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding Command}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Image>
</Grid>
</UserControl>