Silverlight:按钮上的透明图像
我想在silverlight按钮上使用一个透明的png文件。此外,我希望按钮本身是透明的,以便背景(按钮后面)显示通过。我发现如果我设置按钮的不透明度,它也会影响图像。我不希望整个图像是透明的-只是PNG中定义的透明部分Silverlight:按钮上的透明图像,silverlight,image,button,opacity,Silverlight,Image,Button,Opacity,我想在silverlight按钮上使用一个透明的png文件。此外,我希望按钮本身是透明的,以便背景(按钮后面)显示通过。我发现如果我设置按钮的不透明度,它也会影响图像。我不希望整个图像是透明的-只是PNG中定义的透明部分 关于如何实现这一点有什么想法吗?Silverlight支持png透明。这项工作: <UserControl x:Class="SilverlightApplication17.Page" xmlns="http://schemas.microsoft.com/winfx/
关于如何实现这一点有什么想法吗?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答案中的链接是下降链接。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答案中的链接是下降链接。根据我随后的调查,似乎并非所有透明PNG都能起作用。它们必须是基于alpha的透明胶片(而不是基于调色板)。它们还必须是至少16位的图像。标准8位不起作用。根据我随后的调查,似乎并非所有透明PNG都能起作用。它们必须是基于alpha的透明胶片(而不是基于调色板)。它们还必须是至少16位的图像。标准8位不起作用。
<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>