resources/xaml/styles/ButtonStyle.xaml
|
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!-- Modern Button Style with Smooth Transitions and Depth --> <Style x:Key="ModernButtonStyle" TargetType="Button"> <Setter Property="Background" Value="{DynamicResource ButtonBackgroundBrush}"/> <Setter Property="Foreground" Value="{DynamicResource ButtonForegroundBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Padding" Value="12,6,12,6"/> <Setter Property="FontFamily" Value="Segoe UI"/> <Setter Property="FontSize" Value="12"/> <Setter Property="Cursor" Value="Hand"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Grid> <!-- Main Button Body --> <Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4" SnapsToDevicePixels="true"> <Grid> <!-- Hover Overlay --> <Border x:Name="HoverBorder" Background="{DynamicResource ButtonHoverBackgroundBrush}" Opacity="0" CornerRadius="3" IsHitTestVisible="False"/> <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Grid> </Border> <!-- Visual State Manager for Smooth Transitions --> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"> <Storyboard> <DoubleAnimation Storyboard.TargetName="HoverBorder" Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.15"/> <ThicknessAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="Margin" To="0" Duration="0:0:0.15"/> </Storyboard> </VisualState> <VisualState x:Name="MouseOver"> <Storyboard> <DoubleAnimation Storyboard.TargetName="HoverBorder" Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.1"/> </Storyboard> </VisualState> <VisualState x:Name="Pressed"> <Storyboard> <DoubleAnimation Storyboard.TargetName="HoverBorder" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/> <ThicknessAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="Margin" To="0,1,0,0" Duration="0"/> </Storyboard> </VisualState> <VisualState x:Name="Disabled"> <Storyboard> <DoubleAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="Opacity" To="0.6" Duration="0"/> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> </Grid> <ControlTemplate.Triggers> <!-- Fallback triggers if VSM isn't fully supported in some contexts --> <Trigger Property="IsMouseOver" Value="true"> <Setter TargetName="HoverBorder" Property="Opacity" Value="1"/> </Trigger> <Trigger Property="IsPressed" Value="true"> <Setter TargetName="HoverBorder" Property="Opacity" Value="1"/> <Setter TargetName="border" Property="Margin" Value="0,1,0,0"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> |