[WPF] button按键的透明设置

WPF 如何将button始终设置为透明色,实际效果如下:
在这里插入图片描述

button为透明效果的设定,需要先将button的背景设置为透明,然后在鼠标移动到button上之后也设置为透明;
具体方法如下:

1,在MainWindow.xaml中添加自定义style功能;

<Window.Resources>
        <Style x:Key="MyButton" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Name="border" BorderThickness="0" Background="{TemplateBinding Background}">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Opacity" Value="0.55" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>

2,在button中调用 style属性 注意此处用 DynamicResource前置属性;

        <Button x:Name="actbt" Style="{DynamicResource MyButton}" Content="开始" Height="60" Margin="0,0,0,100" VerticalAlignment="Bottom" RenderTransformOrigin="0.481,0.544" Click="actbt_Click" Background="{x:Null}" BorderBrush="{x:Null}" FontFamily="STKaiti" FontSize="24" Foreground="Yellow" FontWeight="Bold" Width="120"/>

参考连接:https://blog.csdn.net/joycesunny/article/details/91125911

【好文共赏析!】

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值