转帖链接:https://www.itsvse.com/thread-3348-1-1.html

新建Style.xaml,将一下代码填入,xmlns:local改为自己的

  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:local="clr-namespace:WpfTest">
  4. <Style x:Key="RoundedGelButton" TargetType="Button">
  5. <Setter Property="Width" Value="100"/>
  6. <Setter Property="Height" Value="100"/>
  7. <Setter Property="Foreground" Value="White"/>
  8. <Setter Property="Template">
  9. <Setter.Value>
  10. <ControlTemplate TargetType="{x:Type Button}">
  11. <Grid>
  12. <Ellipse Name="GelBackground" StrokeThickness="0.5" Fill="Black">
  13. <Ellipse.Stroke>
  14. <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
  15. <GradientStop Offset="0" Color="#ff7e7e7e"></GradientStop>
  16. <GradientStop Offset="1" Color="Black"></GradientStop>
  17. </LinearGradientBrush>
  18. </Ellipse.Stroke>
  19. </Ellipse>
  20. <Ellipse Margin="15,5,15,50">
  21. <Ellipse.Fill>
  22. <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
  23. <GradientStop Offset="0" Color="#aaffffff"></GradientStop>
  24. <GradientStop Offset="1" Color="Transparent"></GradientStop>
  25. </LinearGradientBrush>
  26. </Ellipse.Fill>
  27. </Ellipse>
  28. <ContentPresenter Name="GelButtonContent" VerticalAlignment="Center" HorizontalAlignment="Center"
  29. Content="{TemplateBinding Content}"/>
  30. </Grid>
  31. <ControlTemplate.Triggers>
  32. <Trigger Property="IsMouseOver" Value="True">
  33. <Setter Property="Ellipse.Fill" TargetName="GelBackground">
  34. <Setter.Value>
  35. <RadialGradientBrush>
  36. <GradientStop Offset="0" Color="Lime"></GradientStop>
  37. <GradientStop Offset="1" Color="DarkGreen"></GradientStop>
  38. </RadialGradientBrush>
  39. </Setter.Value>
  40. </Setter>
  41. </Trigger>
  42. <Trigger Property="IsPressed" Value="True">
  43. <Setter Property="Ellipse.Fill" TargetName="GelBackground">
  44. <Setter.Value>
  45. <RadialGradientBrush>
  46. <GradientStop Offset="0" Color="#ffcc34"></GradientStop>
  47. <GradientStop Offset="1" Color="#cc9900"></GradientStop>
  48. </RadialGradientBrush>
  49. </Setter.Value>
  50. </Setter>
  51. </Trigger>
  52. </ControlTemplate.Triggers>
  53. </ControlTemplate>
  54. </Setter.Value>
  55. </Setter>
  56. </Style>
  57. </ResourceDictionary>

在App.xmal文件中添加此资源文件

ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Style.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

在界面中使用

<Button Style="{StaticResource RoundedGelButton}" Content="Click Me!"></Button>

local, Style, 资源

WPF自定义圆形按钮样式相关推荐

  1. WPF 自定义CheckBox样式

    引: WPF 自定义CheckBox样式 - 一叶知秋,知寒冬 - 博客园 Checkbox基本样式 下面的样式包含了CheckBox三种状态的显示,这里CheckBox的三种状态是使用图片代替的.当 ...

  2. WPF 自定义 ToggleButton 样式

    UI 设计中经常会用到 Toggle Button,用于切换不同的状态. UWP 中有 ToggleSwitch, 长这样: WPF 中有 ToggleButton, 长这样: 嗯?????(黑人问号 ...

  3. WPF自定义Slider样式外观 实现酷狗播放进度条

    自定义滑块左边和右边的样式以及滑块的样式 关键代码有注释说明 效果: VS2015下测试: VSBlend生成的模板 <Style x:Key="SliderStyle2" ...

  4. WPF 自定义ToggleButton样式

    废话不多说! 样式显示如图 源代码奉上: <LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint=& ...

  5. WPF 自定义Expander样式

    先看效果 样式代码如下: <Style x:Key="ExpanderStyle" TargetType="{x:Type Expander}">& ...

  6. WPF自定义控件与样式(8)-ComboBox与自定义多选控件MultComboBox

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 下拉选 ...

  7. WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展

    原文:WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展 一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐 ...

  8. WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式

    原文:WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式 一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等, ...

  9. 【C#】wpf自定义calendar日期选择控件的样式

    原文:[C#]wpf自定义calendar日期选择控件的样式 首先上图看下样式 原理 总览 ItemsControl内容的生成 实现 界面的实现 后台ViewModel的实现 首先上图,看下样式 原理 ...

最新文章

  1. vue全家桶+Koa2开发笔记(5)--nuxt
  2. 怎样使用fastJson发送数组格式的Json数据
  3. 处理selinux方法
  4. SAP Spartacus Sample Data Extension
  5. js中的==与===的区别
  6. 动手学CV-目标检测入门教程6:训练与测试
  7. MySQL优化建议汇总~~~
  8. /etc/fstab 文件配置项简单介绍
  9. 演练 可以飞可以喷火的人 java
  10. jdeveloper12.1.3的安装与卸载
  11. 从环境搭建探讨做事的方法
  12. 多个checkbox 回显
  13. R语言绘图大小及图例问题
  14. #低码系列#如何设计一个低代码平台?
  15. ds18b20触摸没反应_关于DS18B20无法正常使用的问题
  16. vue 获取元素宽高
  17. ps3slim安装linux,PS3 Slim配置详解 新旧款真机对比
  18. 珠海拱北口岸停车攻略,拱北口岸地下停车场收费
  19. ESP32C3 WiFi 连接
  20. 基于浏览器的交互式Go学习平台 | Gopher Daily (2020.11.14) ʕ◔ϖ◔ʔ

热门文章

  1. 130、RPC远程过程调用
  2. vol.146 生活这么苦,为什么你们还要玩更苦的游戏
  3. python微信群定时发早安_Python每天定时发早安晚安语录
  4. 探究NFC SWP移动支付技术
  5. Shell命令之expect
  6. Linux内核中的jiffies详解
  7. freecel 空档接龙 算法
  8. 送小仙女一个手持稳定器,总算达成了心愿,嘿嘿
  9. x86-SSE指令集
  10. 最奇特的编程语言特征