先上效果图:

这个控件其实是俩个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}" />

RadioButton改写的开关按钮的更多相关文章

  1. SwitchButton 开关按钮 的多种实现方式

    刚开始接触开关样式的按钮是在IOS系统上面,它的切换以及滑动十分帅气,深入人心. 所谓的开关按钮,就是只有2个状态:on和off,下图就是系统IOS 7上开关按钮效果. 起初我在android上我只会 ...

  2. 【Android自定义控件】支持多层嵌套RadioButton的RadioGroup

    前言 非常喜欢用RadioButton+RadioGroup做Tabs,能自动处理选中等效果,但是自带的RadioGroup不支持嵌套RadioButton(从源码可看出仅仅是判断子控件是不是Radi ...

  3. Android——复选按钮和开关按钮

    复选按钮和开关按钮代码如下: <LinearLayout android:layout_width="match_parent" android:layout_height= ...

  4. 单选按钮(RadioButton)与复选框(CheckBox)的功能与用法

    单选按钮(RadioButton)和复选框(CheckBox).状态开关按钮(ToggleButton)与开关(Switch)是用户界面中最普通的UI组件,他们都继承了Button类,因此都可直接使用 ...

  5. SwitchButton 开关按钮 的多种实现方式 (附源码DEMO)

    http://blog.csdn.net/vipzjyno1/article/details/23707149 Switch开关android源码SwitchButton 刚开始接触开关样式的按钮是在 ...

  6. 通过改写 原始对象的paint 方法,来设置对象的border颜色

    解决方案: //通过改写 原始对象的paint 方法,来设置对象的border颜色 1. package test1;import java.awt.Color;import java.awt.Gra ...

  7. 为Xamarin更好的开发而改写的库

    欢迎大家加入以下开源社区 Xamarin-Cn:https://github.com/Xamarin-Cn Mvvmcross-Cn:https://github.com/Mvvmcross-Cn  ...

  8. Android动画:模拟开关按钮点击打开动画(属性动画之平移动画)

    在Android里面,一些炫酷的动画确实是很吸引人的地方,让然看了就赏心悦目,一个好看的动画可能会提高用户对软件的使用率.另外说到动画,在Android里面支持3种动画: 逐帧动画(Frame Ani ...

  9. RadioButton与CheckBox

    笔者长期从事于数据库的开发,算了,不提当年了,因为一直用的是小语种(PowerBuilder),还是来说说这两个最常见的控件吧! RadioButton(单选)和CheckBox(多选) 先来看看继承 ...

随机推荐

  1. MYGUI3.2改造——完善windows下的文字显示

    MYGUI 3.2 是支持中文显示的——往“MyGUI_Fonts.xml”文件里添加上中文的编码范围即可,这个网上有很多. 能显示中文后,再添加中文的自动换行,这个网上有:http://blog.s ...

  2. AOP编程实践总结

    AOP编程实践总结 AOP概述 AOP(Aspect-Oriented Programming,面向方面编程)是OOP(Object-Oriented Programing,面向对象编程)的补充和完善 ...

  3. Shell常用脚本之用户操作

    批量创建10个系统帐号oldboy01-oldboy10并设置密码,密码为随机8位字符串 #!/bin/bash ..} do useradd $user -] | ` | passwd --stdi ...

  4. Java 程序是如何执行的

    Java 程序是如何执行的 了解任何一门语言的精髓都是先俯览其全貌,从宏观的视角把握全局,然后再深入每个知识点逐个击破,这样就可以深入而快速的掌握一项技能.同样学习 Java 也是如此,本节就让我们先 ...

  5. <背包>solution-CF118D_Caesar's Legions

    Caesar's Legions Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the a ...

  6. 逆向番茄社区app的rsa加密方式

    Parse RSA public and private key pair from string in Java 逆向某APP,发现其大部分配置文件都是加密的 .所以逆向算法并解密 RSA和AES密 ...

  7. session、cookie、sessionStorage、localStorage的简要理解

    一.cookie和session 首先 session 和 cookie 用于浏览器客户端与服务端数据交互,通过会话的方式跟踪浏览器用户身份. 1.cookie (1).一般由服务器生成,可以设置失效 ...

  8. 16、ISDN

    ISDN:综合业务数据网 分类:1.宽带ISDN:基本上被淘汰2.窄带ISDN:用于备份链路,速率比较低 ISDN的起源和优点 ISDN能够提供声音.视频.数据等传输业务 ISDN的两种服务方式ISD ...

  9. linux入门系列11--Centos7网络服务管理

    通过前面文章的学习已经掌握了Linux系统配置管理的知识,本文讲解Centos7网络配置知识. Linux要对外提供服务,需要保证网络通信正常,因此需要正确配置网络参数.本文将讲解如何使用Networ ...

  10. 这个 Spring 循环依赖的坑,90% 以上的人都不知道

    1. 前言 这两天工作遇到了一个挺有意思的Spring循环依赖的问题,但是这个和以往遇到的循环依赖问题都不太一样,隐藏的相当隐蔽,网络上也很少看到有其他人遇到类似的问题.这里权且称他非典型Spring ...