先上效果图:

这个控件其实是俩个RadioButton,通过样式就可以实现。

样式资源:

 <Style x:Key="Tong_Yong_RadioButtonStyle" TargetType="{x:Type RadioButton}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="Background" Value="White" />
<Setter Property="BorderThickness" Value="" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Padding" Value="" />
<Setter Property="Margin" Value="10,10,0,0" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Height" Value="{Binding Height}" />
<Setter Property="Width" Value="{Binding Width}" />
<Setter Property="Cursor" Value="Hand" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid>
<!-- 选中或者鼠标移入颜色 -->
<Grid
x:Name="B"
Background="#0099ff"
Visibility="Collapsed" />
<!-- 默认颜色 -->
<Grid x:Name="A" Background="{TemplateBinding Background}" /> <ContentPresenter
x:Name="b"
HorizontalAlignment="Center"
VerticalAlignment="Center"
TextBlock.Foreground="White" />
<ContentPresenter
x:Name="a"
HorizontalAlignment="Center"
VerticalAlignment="Center"
TextBlock.Foreground="Black" />
</Grid>
                <ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="A" Property="Visibility" Value="Collapsed" />
<Setter TargetName="B" Property="Visibility" Value="Visible" />
<Setter TargetName="a" Property="Visibility" Value="Collapsed" />
<Setter TargetName="b" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

2.引用样式

 <RadioButton
Width=""
Margin=""
Content="开"
Foreground="Black"
Style="{DynamicResource Tong_Yong_RadioButtonStyle}" />
<RadioButton
Width=""
Margin=""
Content="关"
Foreground="Black"
IsChecked="True"
Style="{DynamicResource Tong_Yong_RadioButtonStyle}" />

最新文章

  1. Android中使用ViewPager实现屏幕页面切换和页面切换效果
  2. java三大框架
  3. js实现div层缓慢收缩与展开的方法
  4. DragLayout: QQ5.0侧拉菜单的新特效
  5. Python练习题 027:对10个数字进行排序
  6. AVR ATMEGA8 串口USART
  7. 不关闭seLinux解决vsftpd服务本地用户不能登录问题(500 OOPS: cannot change directory:/home/***
  8. 运行yum报错:Error: Cannot retrieve metalink for repository: epel. Please verify its path
  9. 安装 SQL Server2008 安装程序规则支持提示“重新启动计算机”失败
  10. 浅谈 js 数字格式类型
  11. iOS获取设备唯一标识的各种方法?IDFA、IDFV、UDID分别是什么含义?
  12. Java之StringBuffer,StringBuilder,Math,Date,SimpleDateFormat,UUID,File
  13. Ubuntu 12.04 LTS 查看网关地址方法汇总
  14. 安装FrameWork后重新注册IIS
  15. odoo开发笔记--form视图自定义
  16. 【mongo】登陆报错
  17. python+requests接口自动化完整项目设计源码
  18. java se 随机数。生成
  19. 查找第K小的元素(利用中位数线性时间选择)(C)
  20. 20145330 《网络攻防》 MSF基础应用

热门文章

  1. Python学习,第四课 - 字符串相关操作
  2. selenium,CSS定位法应用
  3. qq机器人 python实现 自动回复
  4. HBase学习总结
  5. 多线程之CountDownLatch的用法及原理笔记
  6. python学习Day05--字典
  7. C++ 类模板详解(一):概念和基本使用方式
  8. linux笔记之解压
  9. WeChall_Training: ASCII (Training, Encoding)
  10. 使用canvas制作五子棋游戏