版权声明:欢迎分享 https://blog.csdn.net/qq_42791845/article/details/83141083
样式代码
<Style x:Key="btnTransparentStyle" TargetType="Button">
<Setter Property="Width" Value="130"/>
<Setter Property="Height" Value="46"/>
<!--<Setter Property="Margin" Value="50,15"/>-->
<!--<Setter Property="Foreground" Value="White"/>-->
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Background" Value="Transparent"/> //透明属性
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="border" CornerRadius="10" Background="{TemplateBinding Background}" BorderBrush="LightGray" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
<TextBlock x:Name="Block" Text="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center" HorizontalAlignment="Center" FontWeight="Normal" FontSize="{TemplateBinding FontSize}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">//指针移到上方按钮变色
<Setter TargetName="border" Property="BorderBrush" Value="Green"/>
<Setter TargetName="Block" Property="Foreground" Value="Green"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">//指针点击效果
<Setter TargetName="border" Property="BorderBrush" Value="LightGray"/>
<Setter TargetName="Block" Property="Foreground" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
原始效果
指针悬停效果
点击效果