【问题标题】:Silverlight: Transparent image on buttonSilverlight:按钮上的透明图像
【发布时间】:2010-10-02 00:30:30
【问题描述】:

我想在 silverlight 按钮上使用透明 png 文件。此外,我希望按钮本身是透明的,以便背景(按钮后面)显示出来。我发现如果我设置按钮的不透明度,它也会影响图像。我不希望整个图像都是透明的 - 只是 PNG 中定义的透明部分。

关于如何实现这一点的任何想法?

【问题讨论】:

    标签: silverlight image button opacity


    【解决方案1】:
    <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>
    

    【讨论】:

      【解决方案2】:

      从我随后的调查来看,似乎并非所有透明 PNG 都能正常工作。它们必须是基于 alpha 的透明胶片(而不是基于调色板)。它们还必须是至少 16 位的图像。标准的 8 位不工作。

      【讨论】:

        【解决方案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 的答案中的链接是血统。

        【讨论】:

          猜你喜欢
          • 2011-06-09
          • 2019-09-21
          • 2020-06-11
          • 1970-01-01
          • 1970-01-01
          • 2017-11-04
          • 2021-09-18
          • 1970-01-01
          • 2019-12-13
          相关资源
          最近更新 更多