博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
漂亮的按钮样式-button
阅读量:6278 次
发布时间:2019-06-22

本文共 8793 字,大约阅读时间需要 29 分钟。

 <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>

转载于:https://www.cnblogs.com/shyyj/archive/2012/02/09/2344137.html

你可能感兴趣的文章
Android 密钥保护和 C/S 网络传输安全理论指南
查看>>
以太坊ERC20代币合约优化版
查看>>
Why I Began
查看>>
同一台电脑上Windows 7和Ubuntu 14.04的CPU温度和GPU温度对比
查看>>
js数组的操作
查看>>
springmvc Could not write content: No serializer
查看>>
Python系语言发展综述
查看>>
新手 开博
查看>>
借助开源工具高效完成Java应用的运行分析
查看>>
163 yum
查看>>
第三章:Shiro的配置——深入浅出学Shiro细粒度权限开发框架
查看>>
80后创业的经验谈(转,朴实但实用!推荐)
查看>>
让Windows图片查看器和windows资源管理器显示WebP格式
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
vim使用点滴
查看>>
embedded linux学习中几个需要明确的概念
查看>>
mysql常用语法
查看>>
Morris ajax
查看>>
【Docker学习笔记(四)】通过Nginx镜像快速搭建静态网站
查看>>