废话不多说!

样式显示如图

源代码奉上:

<LinearGradientBrush x:Key="ButtonNormalBackgroundFill" EndPoint="0.5,1" StartPoint="0.5,0"><GradientStop Color="#FFFFFFFF" Offset="0"/><GradientStop Color="#FFF0F0EA" Offset="0.9"/></LinearGradientBrush><SolidColorBrush x:Key="ButtonBorder" Color="#FF003C74"/><Style x:Key="ToggleButtonStyle1" TargetType="{x:Type ToggleButton}"><Setter Property="FocusVisualStyle" Value="{x:Null}"/><Setter Property="Background" Value="{StaticResource ButtonNormalBackgroundFill}"/><Setter Property="BorderBrush" Value="{StaticResource ButtonBorder}"/><Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/><Setter Property="HorizontalContentAlignment" Value="Center"/><Setter Property="VerticalContentAlignment" Value="Center"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type ToggleButton}"><ControlTemplate.Resources><Storyboard x:Key="OnChecked1"><ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path"><EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="40,0,0,0"/></ThicknessAnimationUsingKeyFrames><ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path1"><EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="40,0,0,0"/></ThicknessAnimationUsingKeyFrames><ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path2"><EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="40,0,0,0"/></ThicknessAnimationUsingKeyFrames><StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="displayText"><DiscreteStringKeyFrame KeyTime="0" Value="OFF"/></StringAnimationUsingKeyFrames></Storyboard><Storyboard x:Key="OnUnchecked1"><ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path"><EasingThicknessKeyFrame KeyTime="0" Value="40,0,0,0"/><EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="0"/></ThicknessAnimationUsingKeyFrames><ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path1"><EasingThicknessKeyFrame KeyTime="0" Value="40,0,0,0"/><EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="0"/></ThicknessAnimationUsingKeyFrames><ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="path2"><EasingThicknessKeyFrame KeyTime="0" Value="40,0,0,0"/><EasingThicknessKeyFrame KeyTime="0:0:0.5" Value="0"/></ThicknessAnimationUsingKeyFrames><StringAnimationUsingKeyFrames Storyboard.TargetProperty="(TextBlock.Text)" Storyboard.TargetName="displayText"><DiscreteStringKeyFrame KeyTime="0" Value="ON"/></StringAnimationUsingKeyFrames><ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="displayText"><EasingColorKeyFrame KeyTime="0" Value="White"/><EasingColorKeyFrame KeyTime="0:0:0.5" Value="#FF63FA00"/></ColorAnimationUsingKeyFrames></Storyboard></ControlTemplate.Resources><Border CornerRadius="10" Background="#FF3B3939" Width="60" Height="20"><Grid><TextBlock x:Name="displayText" Text="ON" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock><Path x:Name="path2" Fill="Black"><Path.Data><GeometryGroup><GeometryGroup.Children><EllipseGeometry Center="10,10" RadiusX="8.5" RadiusY="8.5"></EllipseGeometry></GeometryGroup.Children></GeometryGroup></Path.Data></Path><Path x:Name="path1" Fill="#FF818080"><Path.Data><GeometryGroup><GeometryGroup.Children><EllipseGeometry Center="10,10" RadiusX="7" RadiusY="7"></EllipseGeometry></GeometryGroup.Children></GeometryGroup></Path.Data></Path><Path x:Name="path"><Path.Fill><LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"><GradientStop Color="#FF807F7F" Offset="0"/><GradientStop Color="#FF373636" Offset="1"/></LinearGradientBrush></Path.Fill><Path.Data><GeometryGroup><GeometryGroup.Children><EllipseGeometry Center="10,10" RadiusX="8" RadiusY="8"></EllipseGeometry></GeometryGroup.Children></GeometryGroup></Path.Data></Path></Grid></Border><ControlTemplate.Triggers><EventTrigger RoutedEvent="ToggleButton.Checked"><BeginStoryboard Storyboard="{StaticResource OnChecked1}"/></EventTrigger><EventTrigger RoutedEvent="ToggleButton.Unchecked"><BeginStoryboard x:Name="OnUnchecked1_BeginStoryboard" Storyboard="{StaticResource OnUnchecked1}"/></EventTrigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>

WPF 自定义ToggleButton样式相关推荐

  1. WPF 自定义 ToggleButton 样式

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

  2. WPF 自定义CheckBox样式

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

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

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

  4. WPF 自定义Expander样式

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

  5. WPF自定义圆形按钮样式

    转帖链接:https://www.itsvse.com/thread-3348-1-1.html 新建Style.xaml,将一下代码填入,xmlns:local改为自己的 <ResourceD ...

  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. 男生和女生的差别(转载)
  2. 模型压缩6倍,无需重训练:数学家团队提出量化新方法
  3. Android Scroller 使用详解
  4. mysql mysqlhotcopy_MySQL备份工具之mysqlhotcopy
  5. salmap绕waf
  6. [SVN(ubuntu)] ubuntu使用svn
  7. 前端学习(2459):账户设置
  8. SQLServer访问Oracle查询性能问题解决
  9. Fragment试手
  10. Split()函数的作用
  11. 如何修改wifi密码(wifi密码怎么修改在手机上怎么修改)
  12. 敏捷与CMMI的同与不同
  13. 搭建开源物联网平台教程
  14. 种植牙术后的注意事项
  15. 3GPP TS 23501-g51 中英文对照 | 4.4.6 5G LAN-type Services
  16. 【毕设项目问题】IDEA打开springboot项目,启动项上有红色叉叉
  17. 谈谈 雷达信号处理之脉冲压缩
  18. 一个本科渣渣是怎么逆袭从咸鱼到Offer收割机的?大厂面经合集
  19. python统计分析pdf下载_Python金融大数据分析PDF高清文档下载
  20. python定义函数练习题_python练习题

热门文章

  1. 时间序列分析深入总结(一)(附代码)
  2. php 用count 变量,countif函数的使用方法 PHP的可变变量名的使用方法分享
  3. 未来10年云计算发展前景如何?云计算的优势在哪里?
  4. Linux解压short read,LInux之gz文件压缩/解压缩
  5. mac下用户用户组命令行操作
  6. PLC高精度定时器(T法测速功能块)
  7. 微软“黑屏血案”的真相
  8. 专精特新企业认定条件 这些条件要满足
  9. java部门管理_系统管理模块_部门管理_实现基本的增删改查功能
  10. python中import简介