Files
ShrlAlgoToolkit/NeuWPF/NeoUI/Controls/ButtonsStyle.xaml
2025-08-20 12:10:13 +08:00

351 lines
22 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:assists="clr-namespace:NeumUI.Assists"
xmlns:controls="clr-namespace:NeumUI.Controls"
xmlns:svd="clr-namespace:NeumUI.Controls.Decorations"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/NeumUI;component/Animations/Animations.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- 按钮高亮 -->
<Storyboard x:Key="Button.FocusEffect">
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetName="border"
Storyboard.TargetProperty="Intensity"
To="1" />
<DoubleAnimation
Duration="0"
Storyboard.TargetName="border"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
To="1.01" />
<DoubleAnimation
Duration="0"
Storyboard.TargetName="border"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
To="1.01" />
<BooleanAnimationUsingKeyFrames
Duration="0"
Storyboard.TargetName="border"
Storyboard.TargetProperty="ShaderEnabled">
<DiscreteBooleanKeyFrame KeyTime="0" Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
<!-- 按钮取消高亮 -->
<Storyboard x:Key="Button.LeaveEffect">
<DoubleAnimation
Duration="0:0:0.2"
Storyboard.TargetName="border"
Storyboard.TargetProperty="Intensity"
To="0" />
<DoubleAnimation
Duration="0"
Storyboard.TargetName="border"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
To="1" />
<DoubleAnimation
Duration="0"
Storyboard.TargetName="border"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
To="1" />
<BooleanAnimationUsingKeyFrames
Duration="0:0:0.2"
Storyboard.TargetName="border"
Storyboard.TargetProperty="ShaderEnabled">
<DiscreteBooleanKeyFrame KeyTime="0:0:0.2" Value="False" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
<!-- 按钮按下 -->
<Storyboard x:Key="Button.PressEffect">
<DoubleAnimation
Duration="0"
Storyboard.TargetName="border"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
To="0.99" />
<DoubleAnimation
Duration="0"
Storyboard.TargetName="border"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
To="0.99" />
<DoubleAnimation
Duration="0"
Storyboard.TargetName="border"
Storyboard.TargetProperty="Intensity"
To="0.5" />
</Storyboard>
<!-- 拟态按钮,按下后显示深度效果 -->
<Style TargetType="{x:Type Button}" x:Key="NeuButtonStyle">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Padding" Value="10,4" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<svd:EmbossBorder
Background="{TemplateBinding Background}"
BorderThickness="{TemplateBinding BorderThickness}"
Intensity="0.5"
ShaderEnabled="True"
x:Name="emboss" />
<svd:SlotBorder
Background="{TemplateBinding Background}"
Intensity="0"
Margin="0"
ShaderEnabled="False"
x:Name="slot">
<ContentPresenter
Focusable="False"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
x:Name="contentPresenter" />
</svd:SlotBorder>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsDefaulted" Value="True" />
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Intensity" TargetName="emboss" Value="1" />
<!--<Setter Property="BorderThickness" Value="1" />-->
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="ShaderEnabled" TargetName="slot" Value="True" />
<Setter Property="Intensity" TargetName="slot" Value="0.6" />
<Setter Property="Intensity" TargetName="emboss" Value="0" />
<Setter Property="Foreground" TargetName="slot" Value="{DynamicResource TextSecondaryBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" TargetName="emboss" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="ShaderEnabled" TargetName="emboss" Value="False" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- 普通按钮,浮动 -->
<Style TargetType="{x:Type ButtonBase}" x:Key="ButtonBasic">
<Setter Property="assists:ButtonAssist.AppearanceType" Value="None" />
<Setter Property="assists:ButtonAssist.IconPlacement" Value="Left" />
<Setter Property="assists:ButtonAssist.IsRunning" Value="False" />
<Setter Property="assists:ButtonAssist.Icon" Value="Cr" />
<Setter Property="FocusVisualStyle" Value="{DynamicResource FocusVisual}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderNormalBrush}" />
<Setter Property="assists:ShadingAssist.LightShadowBrush" Value="{DynamicResource LightShadowBrush}" />
<Setter Property="assists:ShadingAssist.DarkShadowBrush" Value="{DynamicResource DarkShadowBrush}" />
<Setter Property="assists:ShadingAssist.DisabledBackground" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter Property="assists:ShadingAssist.DisabledForeground" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="assists:ShadingAssist.LightedBorder" Value="{DynamicResource BorderGradientBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="FontSize" Value="14" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Padding" Value="20,8" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ButtonBase}">
<svd:EmbossBorder
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="4"
DarkShadowBrush="{Binding Path=(assists:ShadingAssist.DarkShadowBrush), RelativeSource={RelativeSource TemplatedParent}}"
Intensity="0"
LightShadowBrush="{Binding Path=(assists:ShadingAssist.LightShadowBrush), RelativeSource={RelativeSource TemplatedParent}}"
Margin="0"
RenderTransformOrigin="0.5,0.5"
ShaderEnabled="False"
SnapsToDevicePixels="True"
x:Name="border">
<DockPanel
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<!-- 前缀 -->
<controls:SymbolIcon
DockPanel.Dock="{Binding Path=(assists:ButtonAssist.IconPlacement), RelativeSource={RelativeSource TemplatedParent}}"
Focusable="False"
Margin="0,0,5,0"
RenderTransformOrigin="0.5,0.5"
Symbol="{Binding Path=(assists:ButtonAssist.Icon), RelativeSource={RelativeSource TemplatedParent}}"
x:Name="Icon">
<controls:SymbolIcon.RenderTransform>
<RotateTransform />
</controls:SymbolIcon.RenderTransform>
</controls:SymbolIcon>
<!-- 内容 -->
<ContentPresenter
Focusable="False"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
TextElement.Foreground="{TemplateBinding Foreground}"
x:Name="contentPresenter" />
</DockPanel>
<svd:EmbossBorder.RenderTransform>
<TransformGroup>
<ScaleTransform />
<SkewTransform />
<RotateTransform />
<TranslateTransform />
</TransformGroup>
</svd:EmbossBorder.RenderTransform>
</svd:EmbossBorder>
<ControlTemplate.Triggers>
<!--<Trigger Property="IsDefaulted" Value="True">
<Setter Property="BorderBrush" TargetName="border"
Value="{StaticResource PrimaryBrush}" />
</Trigger>-->
<!-- 前缀图标可见性 -->
<Trigger Property="assists:ButtonAssist.Icon" Value="Cr">
<Setter Property="Visibility" TargetName="Icon" Value="Collapsed" />
</Trigger>
<!-- 切换边框效果,显示阴影 -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="{Binding Path=(assists:ShadingAssist.LightedBorder), RelativeSource={RelativeSource TemplatedParent}}" />
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource Button.FocusEffect}" x:Name="showEffectBegin" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource Button.LeaveEffect}" />
</Trigger.ExitActions>
</Trigger>
<!-- 缩减阴影,下压效果 -->
<Trigger Property="IsPressed" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource Button.PressEffect}" x:Name="pressBegin" />
</Trigger.EnterActions>
<Trigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="pressBegin" />
</Trigger.ExitActions>
</Trigger>
<!-- 按钮禁用效果 -->
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="border" Value="{Binding Path=(assists:ShadingAssist.DisabledBackground), RelativeSource={RelativeSource TemplatedParent}}" />
<Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{Binding Path=(assists:ShadingAssist.DisabledForeground), RelativeSource={RelativeSource TemplatedParent}}" />
</Trigger>
<DataTrigger Binding="{Binding Path=(assists:ButtonAssist.IsRunning), RelativeSource={RelativeSource Self}}" Value="True">
<Setter Property="assists:ButtonAssist.Icon" Value="ProgressActivity" />
<Setter Property="assists:ButtonAssist.IconPlacement" Value="Right" />
<DataTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource LoadingAnimation}" />
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="LoadingAnimation" />
</DataTrigger.ExitActions>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="assists:ButtonAssist.AppearanceType" Value="{x:Static controls:AppearanceType.Primary}">
<Setter Property="Foreground" Value="{DynamicResource TextOnAccentPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource PrimaryNormalBrush}" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="assists:ShadingAssist.LightShadowBrush" Value="{DynamicResource PrimaryLightShadowBrush}" />
<Setter Property="assists:ShadingAssist.DarkShadowBrush" Value="{DynamicResource PrimaryDarkShadowBrush}" />
<Setter Property="assists:ShadingAssist.DisabledBackground" Value="{DynamicResource PrimaryDisabledBrush}" />
<Setter Property="assists:ShadingAssist.DisabledForeground" Value="{DynamicResource TextOnAccentDisabledBrush}" />
<Setter Property="assists:ShadingAssist.LightedBorder">
<Setter.Value>
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
<GradientStop Color="{DynamicResource PrimaryDefaultColor}" Offset="0" />
<GradientStop Color="Transparent" Offset="0.5" />
<LinearGradientBrush.RelativeTransform>
<RotateTransform Angle="45" CenterX="0.5" CenterY="0.5" />
</LinearGradientBrush.RelativeTransform>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="assists:ButtonAssist.AppearanceType" Value="{x:Static controls:AppearanceType.Info}">
<Setter Property="Foreground" Value="{DynamicResource TextOnAccentPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource InfoBrush}" />
<Setter Property="assists:ShadingAssist.LightShadowBrush" Value="{DynamicResource InfoLightShadowBrush}" />
<Setter Property="assists:ShadingAssist.DarkShadowBrush" Value="{DynamicResource InfoDarkShadowBrush}" />
<Setter Property="assists:ShadingAssist.DisabledBackground" Value="{DynamicResource InfoDisabledBrush}" />
<Setter Property="assists:ShadingAssist.LightedBorder">
<Setter.Value>
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
<GradientStop Color="{DynamicResource InfoColor}" Offset="0" />
<GradientStop Color="Transparent" Offset="0.5" />
<LinearGradientBrush.RelativeTransform>
<RotateTransform Angle="45" CenterX="0.5" CenterY="0.5" />
</LinearGradientBrush.RelativeTransform>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="assists:ButtonAssist.AppearanceType" Value="{x:Static controls:AppearanceType.Error}">
<Setter Property="Foreground" Value="{DynamicResource TextOnAccentPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource ErrorBrush}" />
<Setter Property="assists:ShadingAssist.LightShadowBrush" Value="{DynamicResource ErrorLightShadowBrush}" />
<Setter Property="assists:ShadingAssist.DarkShadowBrush" Value="{DynamicResource ErrorDarkShadowBrush}" />
<Setter Property="assists:ShadingAssist.DisabledBackground" Value="{DynamicResource ErrorDisabledBrush}" />
<Setter Property="assists:ShadingAssist.LightedBorder">
<Setter.Value>
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
<GradientStop Color="{DynamicResource ErrorColor}" Offset="0" />
<GradientStop Color="Transparent" Offset="0.5" />
<LinearGradientBrush.RelativeTransform>
<RotateTransform Angle="45" CenterX="0.5" CenterY="0.5" />
</LinearGradientBrush.RelativeTransform>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="assists:ButtonAssist.AppearanceType" Value="{x:Static controls:AppearanceType.Warning}">
<Setter Property="Foreground" Value="{DynamicResource TextOnAccentPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource WarningBrush}" />
<Setter Property="assists:ShadingAssist.LightShadowBrush" Value="{DynamicResource WarningLightShadowBrush}" />
<Setter Property="assists:ShadingAssist.DarkShadowBrush" Value="{DynamicResource WarningDarkShadowBrush}" />
<Setter Property="assists:ShadingAssist.DisabledBackground" Value="{DynamicResource WarningDisabledBrush}" />
<Setter Property="assists:ShadingAssist.LightedBorder">
<Setter.Value>
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
<GradientStop Color="{DynamicResource WarningColor}" Offset="0" />
<GradientStop Color="Transparent" Offset="0.5" />
<LinearGradientBrush.RelativeTransform>
<RotateTransform Angle="45" CenterX="0.5" CenterY="0.5" />
</LinearGradientBrush.RelativeTransform>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="assists:ButtonAssist.AppearanceType" Value="{x:Static controls:AppearanceType.Success}">
<Setter Property="Foreground" Value="{DynamicResource TextOnAccentPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource SuccessBrush}" />
<Setter Property="assists:ShadingAssist.LightShadowBrush" Value="{DynamicResource SuccessLightShadowBrush}" />
<Setter Property="assists:ShadingAssist.DarkShadowBrush" Value="{DynamicResource SuccessDarkShadowBrush}" />
<Setter Property="assists:ShadingAssist.DisabledBackground" Value="{DynamicResource SuccessDisabledBrush}" />
<Setter Property="assists:ShadingAssist.LightedBorder">
<Setter.Value>
<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
<GradientStop Color="{DynamicResource SuccessColor}" Offset="0" />
<GradientStop Color="Transparent" Offset="0.5" />
<LinearGradientBrush.RelativeTransform>
<RotateTransform Angle="45" CenterX="0.5" CenterY="0.5" />
</LinearGradientBrush.RelativeTransform>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
<!-- 默认按钮 -->
<Style BasedOn="{StaticResource ButtonBasic}" TargetType="{x:Type Button}" />
<!-- 重复按钮 -->
<Style BasedOn="{StaticResource ButtonBasic}" TargetType="{x:Type RepeatButton}" />
</ResourceDictionary>