(1)在App.xaml文件里自定义一个按钮样式 ,"MyWpfButton":

<Application x:Class="WPFCustomerStyleStudy.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"StartupUri="MainWindow.xaml"><Application.Resources><Style x:Key="MyWpfButton" TargetType="{x:Type Button}" ></Style></Application.Resources>
</Application>

(2)自定义按钮的前景色背景色,个人比较喜欢蓝色大气:

tip1:自定义一些颜色,作为按钮的前景色背景色方便重用

tip2:假如选择渐变颜色选择比较相近的两种颜色渐变起来比较好看

*tip3:使用blend工具编辑

<Application x:Class="WPFCustomerStyleStudy.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"StartupUri="MainWindow.xaml"><Application.Resources><!--自定义颜色--><LinearGradientBrush x:Key="LinearGradientBlueBackground" EndPoint="0.5,1" StartPoint="0.5,0"><GradientStop Color="#FF377FED" Offset="0" /><GradientStop Color="#FF074CC0" Offset="1" /></LinearGradientBrush><Color x:Key="MyBtnBorderColor">#FF2D78F4</Color><!--END--><Style x:Key="MyWpfButton" TargetType="{x:Type Button}" ><Setter Property="Background" Value="{StaticResource LinearGradientBlueBackground}"></Setter><Setter Property="Foreground" Value="White"></Setter><Setter Property="BorderBrush" Value="{StaticResource MyBtnBorderColor}"></Setter></Style></Application.Resources>
</Application>

下面给按钮绑定下样式,我们对比下效果:

是不是顿时高大尚了起来呢,运行看看效果你会发现鼠标经过的时候颜色还是原始的颜色,下面我们继续完善。

(3)自定义模板,给按钮添加圆角,鼠标经过背景:

<Application x:Class="WPFCustomerStyleStudy.App"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"StartupUri="MainWindow.xaml"><Application.Resources><!--自定义颜色--><LinearGradientBrush x:Key="LinearGradientBlueBackground" EndPoint="0.5,1" StartPoint="0.5,0"><GradientStop Color="#FF377FED" Offset="0" /><GradientStop Color="#FF074CC0" Offset="1" /></LinearGradientBrush><SolidColorBrush x:Key="MyBtnBorderColor" Color="#FF2D78F4"></SolidColorBrush><SolidColorBrush x:Key="MyBtnHoverBackgroundColor" Color="#FF317EF3"></SolidColorBrush><!--END--><Style x:Key="MyWpfButton" TargetType="{x:Type Button}" ><Setter Property="Background" Value="{StaticResource LinearGradientBlueBackground}"></Setter><Setter Property="Foreground" Value="White"></Setter><Setter Property="BorderBrush" Value="{StaticResource MyBtnBorderColor}"></Setter><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Button}"><Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true" CornerRadius="3,3,3,3"><ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"VerticalAlignment="{TemplateBinding VerticalContentAlignment}"  /></Border><ControlTemplate.Triggers><Trigger Property="IsMouseOver" Value="true"><Setter Property="Background" TargetName="border" Value="{StaticResource MyBtnHoverBackgroundColor}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style></Application.Resources>
</Application>

简单大气的按钮样式就完成了,下面看效果:

转载请注明出处:http://www.cnblogs.com/xinwang/p/4354182.html

重写button样式相关推荐

  1. 维信小程序button样式重写

    2019独角兽企业重金招聘Python工程师标准>>> 一.小程序button默认按钮样式重写 以primary按钮为例: /**重写默认按钮样式**/ button[type='p ...

  2. antd Carousel 重写dot样式

    antd的Carousel走马灯组件的dot也就是下面那个滑动的按钮非常的不起眼. 白色背景的时候完全看不到. 但是我们大部分时候又都是白色背景,于是来自己重写一下样式. 在控制台看了一下,应该是这个 ...

  3. Android移动开发之【Android实战项目】漂亮Button样式

    开发中各种样式的Button,其实这些样式所有的View都可以共用的,可能对于你改变的只有颜色 所有的都是用代码实现 文章目录 边框样式,给你的View加上边框 圆角Button 带点击状态的Butt ...

  4. 重写 button 的创建方法

    重写 button 的创建方法 //sxc时时改变 // self.videoM.progress = progress; // if ([self.videoM.downloadStr isEqua ...

  5. button 样式_Tkinter (3)---Button

    前两天想写文章的时候突然发现自己用的PyCharm坏了,再一详细看原来是360杀毒把自己常用的虚拟环境文件夹给删了,无奈只好重新安装包...今天才弄好...算了,废话不多说,直接进入正题. 咱们在日常 ...

  6. 修改安卓默认的系统button样式,以及其它系统控件的默认样式

    先介绍下修改原理:首先打开位于android.widget包下面的Button.java文件,这里有一句关键的代码如下: public Button(Context context, Attribut ...

  7. html按钮字号,html button样式

    html中按钮的字体颜色怎么设置? html中按钮字体的颜色和设置普通字体的颜色都是一样的,使用color属性就可以实现字体颜色的设置. 有以下两种方法: 方法一:jquery方法加颜色. 工具原料: ...

  8. html中按钮的形状,css button 样式

    css 怎么去掉button默认样式 代码如下: .button{border:0px;background-color:transparent;background-image:url(你自定义背景 ...

  9. php好看的控件,漂亮的css button样式汇总

    在网页设计过程中,程序员们常常需要配合美工来设计页面的美观效果,当然大部分页面风格都是美工的工作.但是按钮button样式,是我们程序员最常用的. 下面我们就给大家介绍一些好看的button样式,大家 ...

最新文章

  1. HTML实现折现图完整源码及效果图
  2. 什么是微分?什么是导数?如何利用微分-导数方程求导数?
  3. Android 中文api (88)——SharedPreferences
  4. python string/list转换
  5. 【linux高级程序设计】(第十一章)System V进程间通信 3
  6. C++中的string 类型占几个字节
  7. VTK:绘制箱形图 BoxChart用法实战
  8. vant toast loading 倒计时_日期倒计时软件哪个好 苹果日期倒计时软件推荐
  9. 遗传算法中的转盘算法
  10. 系统学习深度学习(九)--激活函数总结
  11. CMOS模拟集成电路设计 吴金 学习记录1
  12. 怎么把外部参照合并到图纸_CAD外部参照如何绑定?
  13. UPnP的介绍和理解
  14. 【立创开源】ESP8266制作的1.44寸TFT显示屏太空人天气时钟(st7735)(增加农历显示)(抄作业)
  15. android ios通讯录权限设置,IOS 通讯录的访问和修改的实现
  16. 窗口看门狗与独立看门狗区别
  17. 易语言注册机接码平台对接
  18. 【mybatis源码】 mybatis底层源码分析
  19. 操作系统思考 第三章 虚拟内存
  20. jionlp:一款解析地址信息的神奇 Python 库

热门文章

  1. 我与计算机的作文六百,我和电脑交朋友作文600字
  2. html中label标签的使用
  3. jquery ajax同步
  4. 【MATLAB appdesigner】20_UIAxes中绘图以及操作汇总(良心总结,值得收藏)
  5. Spring-Boot-5-Service层
  6. Unity3D入门: 贴两个材质玩玩
  7. 几分惊喜,几分收获--我的2015年总结
  8. 平板电脑是微型计算机吗,精雕细琢 戴尔XT2平板电脑
  9. vs2015配置python_安装 VS2017 并卸载 VS2015 之后 Python 出现严重兼容性问题
  10. linux查看特定文件属性,Linux 查看文件属性一些命令