UIStandard/UIStandard.Assets/Styles/ButtonStyle.xaml

67 lines
3.2 KiB
Plaintext
Raw Normal View History

2025-04-11 01:24:01 +00:00
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- 定义默认颜色 -->
<SolidColorBrush x:Key="NormalColor" Color="Transparent"/>
<SolidColorBrush x:Key="HoverColor" Color="#FFEEEEEE"/>
<SolidColorBrush x:Key="PressedColor" Color="#FFDFDFDF"/>
<!-- 封装按钮样式 -->
<Style x:Key="SystemButtonStyle" TargetType="Button">
<!-- 重置关键属性 -->
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<!-- 使用双层布局确保事件穿透 -->
<Grid x:Name="RootGrid"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<!-- 悬停效果层(必须放在内容层下方) -->
<Border x:Name="HoverLayer"
Background="Transparent"
CornerRadius="4"
Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}}"
Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Grid}}"/>
<!-- 内容容器(强制填充布局) -->
<ContentPresenter x:Name="ContentHost"
HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="True"/>
</Grid>
<!-- 交互状态管理 -->
<ControlTemplate.Triggers>
<!-- 鼠标悬停 -->
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="HoverLayer"
Property="Background"
Value="#20000000"/>
</Trigger>
<!-- 按钮按下 -->
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="HoverLayer"
Property="Background"
Value="#40000000"/>
<Setter TargetName="RootGrid"
Property="RenderTransform">
<Setter.Value>
<ScaleTransform ScaleX="0.95" ScaleY="0.95"/>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>