<Window x:Class="WpfApp120.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp120" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Window.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="FocusVisualStyle" Value="{x:Null}"/> <Setter Property="Background" Value="Black"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid RenderTransformOrigin="0.5,0.5"> <VisualStateManager.VisualStateGroups> <VisualStateGroup Name="commonStates"> <VisualState x:Name="normal"/> <VisualState Name="mouseOver"> <Storyboard> <ColorAnimation Storyboard.TargetName="outerCircle" Storyboard.TargetProperty="(Ellipse.Fill).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" To="Orange" Duration="0:0:0.4"/> </Storyboard> </VisualState> <VisualState x:Name="pressed"> <Storyboard> <DoubleAnimation Storyboard.TargetName="scaleTransform" Storyboard.TargetProperty="ScaleX" To="0.9" Duration="0"/> <DoubleAnimation Storyboard.TargetName="scaleTransform" Storyboard.TargetProperty="ScaleY" To="0.9" Duration="0"/> </Storyboard> </VisualState> <VisualState x:Name="disabled"> <Storyboard> <ColorAnimation Storyboard.TargetName="outerCircle" Storyboard.TargetProperty="(Ellipse.Fill).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)" To="Gray" Duration="0:0:4"/> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="focusStates"> <VisualState x:Name="unFocused"/> <VisualState x:Name="focused"> <Storyboard> <DoubleAnimation Storyboard.TargetProperty="(Grid.RenderTransform).(TransformGroup.Children)[1].(TranslateTransform.Y)" To="-20" AutoReverse="True" RepeatBehavior="Forever" Duration="0:0:4"> <DoubleAnimation.EasingFunction> <QuadraticEase/> </DoubleAnimation.EasingFunction> </DoubleAnimation> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid.RenderTransform> <TransformGroup> <ScaleTransform x:Name="scaleTransform"/> <TranslateTransform x:Name="translateTransform"/> </TransformGroup> </Grid.RenderTransform> <Ellipse x:Name="outterCircle"> <Ellipse.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> <GradientStop Offset="0" Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background.Color}"/> <GradientStop x:Name="highlightGradientStop" Offset="1" Color="Red"/> </LinearGradientBrush> </Ellipse.Fill> </Ellipse> <Ellipse RenderTransformOrigin="0.5,0.5"> <Ellipse.RenderTransform> <ScaleTransform ScaleX="0.8" ScaleY="0.8"/> </Ellipse.RenderTransform> <Ellipse.Fill> <LinearGradientBrush StartPoint="0,0" EndPoint="0,1" > <GradientStop Offset="0" Color="White"/> <GradientStop Offset="1" Color="Transparent"/> </LinearGradientBrush> </Ellipse.Fill> </Ellipse> <Viewbox> <ContentPresenter Margin="{TemplateBinding Padding}"/> </Viewbox> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="outterCircle" Property="Fill" Value="Orange"/> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="RenderTransform"> <Setter.Value> <ScaleTransform ScaleX="0.9" ScaleY="0.9"/> </Setter.Value> </Setter> <Setter Property="RenderTransformOrigin" Value="0.5,0.5"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <Button Content="OK" Width="200" Height="200"/> </Grid> </Window>
标签:VisualState,VisualStateManager,VisualStateGroups,ColorAnimation,WPF From: https://www.cnblogs.com/Fred1987/p/18641595