Files
Shrlalgo.RvKits/AntdWpf/Styles/Button.xaml
2025-07-12 23:31:32 +08:00

208 lines
13 KiB
XML

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:AntdWpf.Controls"
xmlns:helpers="clr-namespace:AntdWpf.Helpers">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AntdWpf;component/Styles/Converters.xaml" />
<ResourceDictionary Source="pack://application:,,,/AntdWpf;component/Styles/Animations.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type controls:AntButton}">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="FontSize" Value="{DynamicResource FontSizeBase}" />
<Setter Property="Height" Value="{DynamicResource ButtonHeightBase}" />
<Setter Property="EffectBrush" Value="{DynamicResource PrimaryBrush}" />
<Setter Property="Padding" Value="{DynamicResource ButtonPaddingBase}" />
<Setter Property="FontWeight" Value="{DynamicResource ButtonFontWeight}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonDefaultBorder}" />
<Setter Property="Background" Value="{DynamicResource ButtonDefaultBackground}" />
<Setter Property="Foreground" Value="{DynamicResource ButtonDefaultForeground}" />
<Setter Property="BorderThickness" Value="{DynamicResource BorderThicknessBase}" />
<Setter Property="helpers:AntdControl.BorderStyle" Value="{DynamicResource BorderStyleBase}" />
<Setter Property="helpers:AntdControl.CornerRadius" Value="{DynamicResource ButtonBorderRadiusBase}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:AntButton}">
<Grid>
<!-- Effect -->
<Border x:Name="Effect"
Margin="-1"
Opacity="0.4"
Focusable="False"
BorderThickness="0"
BorderBrush="{TemplateBinding EffectBrush}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
CornerRadius="{TemplateBinding helpers:AntdControl.CornerRadius}" />
<!-- Border -->
<controls:AntdBorder x:Name="PART_Border"
UseLayoutRounding="True"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
BorderStyle="{TemplateBinding helpers:AntdControl.BorderStyle}"
CornerRadius="{TemplateBinding helpers:AntdControl.CornerRadius}">
<!-- Content -->
<Grid VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
<Grid.ColumnDefinitions>
<!-- Icon -->
<ColumnDefinition Width="Auto" />
<!-- Content -->
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<controls:Icon x:Name="Icon"
Margin="0 0 8 0"
Focusable="False"
Type="{TemplateBinding Icon}" />
<ContentPresenter x:Name="Content"
Grid.Column="1"
RecognizesAccessKey="True"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" />
</Grid>
</controls:AntdBorder>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0" To="Pressed" />
<VisualTransition GeneratedDuration="0:0:0.3" GeneratedEasingFunction="{StaticResource EaseInOut}" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal" />
<VisualState x:Name="MouseOver" />
<VisualState x:Name="Pressed" />
<VisualState x:Name="Disabled" />
</VisualStateGroup>
<VisualStateGroup x:Name="FocusStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.3" GeneratedEasingFunction="{StaticResource EaseInOut}" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Focused" />
<VisualState x:Name="Unfocused" />
</VisualStateGroup>
<VisualStateGroup x:Name="LoadStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.2" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Loaded">
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity"
To="0.65" />
</Storyboard>
</VisualState>
<VisualState x:Name="Unloaded" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
<ControlTemplate.Triggers>
<!-- Loading State -->
<Trigger Property="Loading" Value="True">
<Setter TargetName="Icon" Property="Type" Value="loading" />
</Trigger>
<!-- Content State -->
<Trigger Property="Content" Value="{x:Null}">
<Setter TargetName="Icon" Property="Margin" Value="0" />
<Setter TargetName="Icon" Property="Grid.ColumnSpan" Value="2" />
</Trigger>
<Trigger SourceName="Icon" Property="Type" Value="{x:Null}">
<Setter TargetName="Content" Property="Grid.Column" Value="0" />
<Setter TargetName="Content" Property="Grid.ColumnSpan" Value="2" />
<Setter TargetName="Icon" Property="Visibility" Value="Collapsed" />
</Trigger>
<!-- Shape Circle -->
<Trigger Property="Shape" Value="Circle">
<Setter TargetName="Icon"
Property="FontSize"
Value="{Binding FontSize, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent},
Converter={StaticResource AdditionConverter}, ConverterParameter=2}" />
</Trigger>
<EventTrigger RoutedEvent="ButtonBase.Click">
<BeginStoryboard Storyboard="{StaticResource Ant.ClickAnimating}" />
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!-- Ghost State -->
<Trigger Property="Ghost" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter Property="BorderBrush" Value="White" />
<Setter Property="Background" Value="Transparent" />
</Trigger>
<!-- Primary -->
<Trigger Property="Type" Value="Primary">
<Setter Property="EffectBrush" Value="{DynamicResource ButtonPrimaryBackground}" />
<Setter Property="Foreground" Value="{DynamicResource ButtonPrimaryForeground}" />
<Setter Property="Background" Value="{DynamicResource ButtonPrimaryBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonPrimaryBackground}" />
</Trigger>
<!-- Dashed -->
<Trigger Property="Type" Value="Dashed">
<Setter Property="helpers:AntdControl.BorderStyle" Value="Dashed" />
</Trigger>
<!-- Danger -->
<Trigger Property="Type" Value="Danger">
<Setter Property="EffectBrush" Value="{DynamicResource ButtonDangerForeground}" />
<Setter Property="Foreground" Value="{DynamicResource ButtonDangerForeground}" />
<Setter Property="Background" Value="{DynamicResource ButtonDangerBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonDangerBorder}" />
</Trigger>
<!-- Size -->
<Trigger Property="Size" Value="Large">
<Setter Property="Height" Value="{DynamicResource ButtonHeightLarge}" />
<Setter Property="Padding" Value="{DynamicResource ButtonPaddingLarge}" />
<Setter Property="FontSize" Value="{DynamicResource ButtonFontSizeLarge}" />
</Trigger>
<Trigger Property="Size" Value="Small">
<Setter Property="Height" Value="{DynamicResource ButtonHeightSmall}" />
<Setter Property="Padding" Value="{DynamicResource ButtonPaddingSmall}" />
<Setter Property="FontSize" Value="{DynamicResource ButtonFontSizeSmall}" />
<Setter Property="helpers:AntdControl.CornerRadius" Value="{DynamicResource ButtonBorderRadiusSmall}" />
</Trigger>
<!-- Shape Circle -->
<Trigger Property="Shape" Value="Circle">
<Setter Property="Padding" Value="0" />
<Setter Property="Width" Value="{Binding Height, Mode=OneWay, RelativeSource={RelativeSource Self}}" />
<Setter Property="helpers:AntdControl.CornerRadius" Value="{Binding Height, Mode=OneWay, RelativeSource={RelativeSource Self},
Converter={StaticResource DoubleToCornerRadiusConverter}, ConverterParameter=2}" />
</Trigger>
<!-- Loading State -->
<Trigger Property="Loading" Value="True">
<Setter Property="IsEnabled" Value="False" />
</Trigger>
<!-- Ghost States -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Ghost" Value="True" />
<Condition Property="Type" Value="Primary" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource ButtonPrimaryBackground}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Ghost" Value="True" />
<Condition Property="Type" Value="Danger" />
</MultiTrigger.Conditions>
<Setter Property="BorderBrush" Value="{DynamicResource ButtonDangerForeground}" />
</MultiTrigger>
<!-- Disabled -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Loading" Value="False" />
<Condition Property="IsEnabled" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource ButtonDisableForeground}" />
<Setter Property="Background" Value="{DynamicResource ButtonDisableBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ButtonDisableBorder}" />
</MultiTrigger>
</Style.Triggers>
</Style>
</ResourceDictionary>