<Style x:Key="buttonVSM" TargetType="{x:Type Button}">
<!-- 定义样式属性 --> <Setter Property="Foreground" Value="Black" /> <Setter Property="Template"> <Setter.Value> <!-- 定义控件模板 --> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="RootElement" Width="Auto" Height="24" HorizontalAlignment="Stretch" BorderBrush="#FF939393" BorderThickness="1" CornerRadius="2"> <Border.Background> <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <GradientStop x:Name="stop1" Offset="0" Color="#FFF4F4F4" /> <GradientStop x:Name="stop2" Offset="1" Color="#FFF4F4F4" /> <GradientStop x:Name="stop3" Offset="0.483" Color="#FFF4F4F4" /> <GradientStop x:Name="stop4" Offset="0.608" Color="#FFF4F4F4" /> </LinearGradientBrush> </Border.Background> <!-- 视觉状态管理组 --> <sw:VisualStateManager.VisualStateGroups> <sw:VisualStateGroup> <!-- 按钮普通状态 --> <sw:VisualState x:Name="Normal"> <Storyboard> <ThicknessAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(BorderThickness)"> <EasingThicknessKeyFrame KeyTime="0" Value="0" /> </ThicknessAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(CornerRadius)"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <CornerRadius>2</CornerRadius> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="stop1" Storyboard.TargetProperty="Color"> <EasingColorKeyFrame KeyTime="0" Value="Transparent" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="stop2" Storyboard.TargetProperty="Color"> <EasingColorKeyFrame KeyTime="0" Value="#00FBFBFB" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="stop4" Storyboard.TargetProperty="Color"> <EasingColorKeyFrame KeyTime="0" Value="#00C0E6E9" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="stop3" Storyboard.TargetProperty="Color"> <EasingColorKeyFrame KeyTime="0" Value="#00CDEBEE" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(BorderBrush).(SolidColorBrush.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#00000000" /> </ColorAnimationUsingKeyFrames> </Storyboard> </sw:VisualState> <!-- 鼠标经过按钮的状态 --> <sw:VisualState x:Name="Pressed"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Border.CornerRadius)"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <CornerRadius>2</CornerRadius> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <ThicknessAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Border.BorderThickness)"> <EasingThicknessKeyFrame KeyTime="0" Value="1" /> </ThicknessAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="stop2" Storyboard.TargetProperty="Color"> <EasingColorKeyFrame KeyTime="0" Value="#FF92E4F1" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="stop1" Storyboard.TargetProperty="Color"> <EasingColorKeyFrame KeyTime="0" Value="#FDA7E0E9" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#FFF7D639" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="stop3" Storyboard.TargetProperty="Color"> <EasingColorKeyFrame KeyTime="0" Value="#FFEFF3F3" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="stop4" Storyboard.TargetProperty="Color"> <EasingColorKeyFrame KeyTime="0" Value="#FFD5F1F3" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#FFFCE58C" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#FFFCE58C" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#FFFCE58C" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#FFFCE58C" /> </ColorAnimationUsingKeyFrames> </Storyboard> </sw:VisualState> <!-- 按钮按下状态 --> <sw:VisualState x:Name="MouseOver"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetName="stop2" Storyboard.TargetProperty="Color"> <EasingColorKeyFrame KeyTime="0" Value="#FF99D7DC" /> </ColorAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Border.CornerRadius)"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <CornerRadius>2</CornerRadius> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> <ThicknessAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Border.BorderThickness)"> <EasingThicknessKeyFrame KeyTime="0" Value="1" /> </ThicknessAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="stop1" Storyboard.TargetProperty="Color"> <EasingColorKeyFrame KeyTime="0" Value="#FFF7F9F9" /> </ColorAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="stop3" Storyboard.TargetProperty="Offset"> <EasingDoubleKeyFrame KeyTime="0" Value="0.487" /> </DoubleAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#FFF7D639" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[3].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#FFFCE58C" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#FFFCE38A" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[2].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#FFFCF9E0" /> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)"> <EasingColorKeyFrame KeyTime="0" Value="#FFFCF9E0" /> </ColorAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[3].(GradientStop.Offset)"> <EasingDoubleKeyFrame KeyTime="0" Value="0.678" /> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Offset)"> <EasingDoubleKeyFrame KeyTime="0" Value="0" /> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Offset)"> <EasingDoubleKeyFrame KeyTime="0" Value="0.97" /> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[2].(GradientStop.Offset)"> <EasingDoubleKeyFrame KeyTime="0" Value="0" /> </DoubleAnimationUsingKeyFrames> </Storyboard> </sw:VisualState> </sw:VisualStateGroup> </sw:VisualStateManager.VisualStateGroups> <!-- 显示按钮文本 --> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding Content}" /> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>
在页面中运用:
<Button Content="添加新规则" x:Name="button_Add" Style="{StaticResource ResourceKey=buttonVSM}" > </Button>