【问题标题】:WPF button background image with transparency具有透明度的 WPF 按钮背景图像
【发布时间】:2016-08-28 10:07:51
【问题描述】:

我有一个 WPF 按钮
我想为按钮添加图像背景
图像是具有透明度的 PNG
这是我所拥有的:

<Button
    Width="160"
    Height="55"
    BorderThickness="0">
      <Button.Background>
           <ImageBrush ImageSource="C:\images\mute.png" />
      </Button.Background>
                      Mute
</Button>

如何设置背景以允许透明?

【问题讨论】:

  • 不确定是否是拼写错误,但您的问题说图像是png,而代码则不然……图像是什么? jpgpng?
  • @GeoffJames 它的 png。我修好了

标签: wpf xaml button transparency


【解决方案1】:

你的按钮控件应该是这样的:

 <Button Background="Transparent" BorderBrush="Transparent" >
                            <ContentControl>
                                <Image Width="160"
                                 Height="55" Source="C:\images\mute.jpg"  />
                            </ContentControl>
                             Mute
                        </Button>

【讨论】:

  • 这种方式的图像对齐并不完美(其中一些是隐藏的,另一个问题是内容。它应该包含文本“Mute”
  • 你能检查我的编辑吗?您可以根据需要控制高度和宽度,并为按钮提供文本:)
  • 有什么更新吗?我尝试了我的解决方案,它对我很有效:)
  • 当我添加“静音”文本时出现错误:“内容”属性设置不止一次。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-13
  • 2015-05-15
  • 1970-01-01
  • 2017-11-04
  • 2014-12-19
  • 2020-04-08
  • 2016-08-02
相关资源
最近更新 更多