如图所示,定义按钮的样式方式有种;保存按钮的样式代码如下:
<Style TargetType="Button" x:Key="btnToolBar">
<Setter Property="Template">
<Setter.Value>
<!--ControlTemplate指定控件的可视结构和可视行为,可以通过为控件指定新 ControlTemplate 自定义该控件的外观。-->
<ControlTemplate TargetType="{x:Type Button}">
<!--定义控件模板资源 end-->
<!--定义控件模板资源-->
<ControlTemplate.Resources>
<!--定义故事版-->
<Storyboard x:Key="TimeLine1">
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:0.0030000" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="TimeLine2">
<DoubleAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetName="glow" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:0.00300" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<!--自定义该控件button的边框-->
<Border BorderBrush="White" BorderThickness="1,1,1,1" CornerRadius="3">
<Border x:Name="border" Background="SkyBlue" BorderBrush="White" BorderThickness="1" CornerRadius="3" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.507*"/>
<RowDefinition Height="0.493*"/>
</Grid.RowDefinitions>
<Border Opacity="0" HorizontalAlignment="Stretch" x:Name="glow" Width="Auto" Grid.RowSpan="2" CornerRadius="0">
<Border.Background>
<RadialGradientBrush>
<RadialGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform ScaleX="1.702" ScaleY="2.243"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="-0.368" Y="-0.152"/>
</TransformGroup>
</RadialGradientBrush.RelativeTransform>
<GradientStop Color="#B28DBDFF" Offset="0"/>
<GradientStop Color="#008DBDFF" Offset="1"/>
</RadialGradientBrush>
</Border.Background>
</Border>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" Grid.RowSpan="2" Text="{TemplateBinding Content}" TextBlock.Foreground="White"/>
<Border HorizontalAlignment="Stretch" Margin="0" x:Name="shine" Width="Auto" CornerRadius="0,0,3,3">
<Border.Background>
<LinearGradientBrush EndPoint="0.494,0.889" StartPoint="0.494,0.028">
<GradientStop Color="#99FFFFFF" Offset="0"/>
<GradientStop Color="#33FFFFFF" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
</Grid>
</Border>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Opacity" Value="0.4"/>
<Setter Property="Background" TargetName="border" Value="#cc000000"/>
<Setter Property="Visibility" TargetName="glow" Value="Hidden"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource TimeLine1}"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard x:Name="Timeline2_BeginStoryboard" Storyboard="{StaticResource TimeLine2}"/>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>