RadioButton改写的开关按钮
先上效果图:

这个控件其实是俩个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改写的开关按钮的更多相关文章
- SwitchButton 开关按钮 的多种实现方式
刚开始接触开关样式的按钮是在IOS系统上面,它的切换以及滑动十分帅气,深入人心. 所谓的开关按钮,就是只有2个状态:on和off,下图就是系统IOS 7上开关按钮效果. 起初我在android上我只会 ...
- 【Android自定义控件】支持多层嵌套RadioButton的RadioGroup
前言 非常喜欢用RadioButton+RadioGroup做Tabs,能自动处理选中等效果,但是自带的RadioGroup不支持嵌套RadioButton(从源码可看出仅仅是判断子控件是不是Radi ...
- Android——复选按钮和开关按钮
复选按钮和开关按钮代码如下: <LinearLayout android:layout_width="match_parent" android:layout_height= ...
- 单选按钮(RadioButton)与复选框(CheckBox)的功能与用法
单选按钮(RadioButton)和复选框(CheckBox).状态开关按钮(ToggleButton)与开关(Switch)是用户界面中最普通的UI组件,他们都继承了Button类,因此都可直接使用 ...
- SwitchButton 开关按钮 的多种实现方式 (附源码DEMO)
http://blog.csdn.net/vipzjyno1/article/details/23707149 Switch开关android源码SwitchButton 刚开始接触开关样式的按钮是在 ...
- 通过改写 原始对象的paint 方法,来设置对象的border颜色
解决方案: //通过改写 原始对象的paint 方法,来设置对象的border颜色 1. package test1;import java.awt.Color;import java.awt.Gra ...
- 为Xamarin更好的开发而改写的库
欢迎大家加入以下开源社区 Xamarin-Cn:https://github.com/Xamarin-Cn Mvvmcross-Cn:https://github.com/Mvvmcross-Cn ...
- Android动画:模拟开关按钮点击打开动画(属性动画之平移动画)
在Android里面,一些炫酷的动画确实是很吸引人的地方,让然看了就赏心悦目,一个好看的动画可能会提高用户对软件的使用率.另外说到动画,在Android里面支持3种动画: 逐帧动画(Frame Ani ...
- RadioButton与CheckBox
笔者长期从事于数据库的开发,算了,不提当年了,因为一直用的是小语种(PowerBuilder),还是来说说这两个最常见的控件吧! RadioButton(单选)和CheckBox(多选) 先来看看继承 ...
随机推荐
- python实例:从excel读取股票代码,爬取股票信息写到代码后面的单元格中
关键词:爬虫.python.request.接口.excel处理 思路: 1.首先准备好excel文档,把股票代码事先编辑进去. 2.脚本读取文档,依次读出股票代码到指定站点发起请求获取股票信息 3. ...
- Nginx配置及负载均衡
转载:http://www.cnblogs.com/jingmoxukong/p/5945200.html nginx简易教程 目录 Nginx 概述 安装与使用 nginx 配置实战 参 ...
- Redis 通用方法 存储DataTable DataRow DataSet
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- HYSBZ_2002_分块
http://www.lydsy.com/JudgeOnline/problem.php?id=2002 分块基础题,初次接触,很巧妙. OJ好像挂了,没法提交. #include<iostre ...
- Java DTO(data transfer object)的理解
首先明白springboot每层 model层 model层即数据库实体层,也被称为entity层,pojo层. 一般数据库一张表对应一个实体类,类属性同表字段一一对应. Model层是数据层: Ta ...
- Django 搭建
1.安装python 2.pip 安装 Django 2.1.3 是版本号 命令:pip install Django==2.1.3 3.数据库驱动: mysql 数据库配置文档: 下载 whl 文 ...
- 使用jQuery的插件jquery.corner.js来实现圆角效果-详解
jquery.corner.js可以实现各种块级元素的角效果,以下为演示,详见jquery_corner.html中的注释部分,并附百度盘下载 jquery_corner.html代码如下: < ...
- java程序设计原则知多少
程序设计七大原则 一.开闭原则 针对我们设计的功能模块对扩展开放,对修改关闭:利用面向接口(抽象)编程(多态的特性),实现对功能需求扩展的同时,不允许更改原来的代码.提高对象的可复用性.可维护性. ...
- 论文《A Generative Entity-Mention Model for Linking Entities with Knowledge Base》
A Generative Entity-Mention Model for Linking Entities with Knowledge Base 一.主要方法 提出了一种生成概率模型,叫做en ...
- web测试和app测试
web测试是b/s结构,app是c/s结构,因此会有很多测试点需要注意: 1.兼容性:web测试需要考虑多个浏览器内核测试,app主要是各种手机(iOS和Android各个型号)不同手机的分辨率.不同 ...