wpf 自定义单选按钮 RadioButton
新建RadioButtonEx.cs
public class RadioButtonEx : RadioButton
{ public Geometry SelectIcon
{
get { return (Geometry)GetValue(SelectIconProperty); }
set { SetValue(SelectIconProperty, value); }
} // Using a DependencyProperty as the backing store for SelectIcon. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SelectIconProperty =
DependencyProperty.Register("SelectIcon", typeof(Geometry), typeof(RadioButtonEx), new PropertyMetadata(default(Geometry))); public Brush IconColor
{
get { return (Brush)GetValue(IconColorProperty); }
set { SetValue(IconColorProperty, value); }
} // Using a DependencyProperty as the backing store for IconColor. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IconColorProperty =
DependencyProperty.Register("IconColor", typeof(Brush), typeof(RadioButtonEx), new PropertyMetadata(Brushes.Red)); /// <summary>
/// 圆角
/// </summary>
public CornerRadius CornerRadius
{
get { return (CornerRadius)GetValue(CornerRadiusProperty); }
set { SetValue(CornerRadiusProperty, value); }
} // Using a DependencyProperty as the backing store for CornerRadius. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CornerRadiusProperty =
DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(RadioButtonEx), new PropertyMetadata(new CornerRadius())); public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
} // Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(RadioButtonEx), new PropertyMetadata("")); }
新建RadioButtonEx资源字典
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ex="clr-namespace:HL.SelfTicket.Controls">
<PathGeometry x:Key="rdbSelect">M431. .782c-11.365 -22.332-4.378-30.589-.286l-235.495-.535c-17.64-16.894-18.245-44.891-1.35-62.528 16.894-17.64 44.891-18.245 62.532-.351l201. 192.552 364.692-.171c15.-18.86 43.39-21.567 62.253-6.049 18.861 15.519 21.568 43.39 6.048 .251l-394.992 .993c-7.821 9.504-19.248 15.319-31.534 16.047-0.874 0.052-1.748 0.078-2.621 .078z</PathGeometry> <Style TargetType="{x:Type ex:RadioButtonEx}">
<Setter Property="Height" Value=""/>
<Setter Property="IconColor" Value="#f14253"/>
<Setter Property="FontSize" Value=""/>
<Setter Property="Foreground" Value="#333"/>
<Setter Property="SelectIcon" Value="{StaticResource rdbSelect}"/>
<Setter Property="BorderThickness" Value=""/>
<Setter Property="BorderBrush" Value="#979797"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ex:RadioButtonEx}">
<Grid x:Name="grid" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<Border Height="{TemplateBinding Height}"
Width="{TemplateBinding Height}"
CornerRadius="{TemplateBinding CornerRadius}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Path Visibility="Collapsed" x:Name="select" Data="{StaticResource rdbSelect}" Margin="" Fill="{TemplateBinding IconColor}" Stretch="Fill"></Path>
</Border>
<TextBlock Text="{TemplateBinding Text}" VerticalAlignment="Center" Margin="10,0,0,0"
Foreground="{TemplateBinding Foreground}" FontSize="{TemplateBinding FontSize}"/>
</StackPanel>
</Grid>
<!--触发器:设置选中状态符号-->
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter Property="Visibility" Value="Visible" TargetName="select"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
原文:https://www.cnblogs.com/zisai/p/11050978.html
wpf 自定义单选按钮 RadioButton的更多相关文章
- wpf 自定义RadioButton控件样式
实现的效果为: 我感觉来自定义RadioButton样式和定义button空间的样式差不多,只是类型不同而已. 接下来分析一下样式代码: <!--自定义单选按钮样式--> & ...
- React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton)
React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton) 一,需求与简单介绍 在开发项目时发现RN没有给提供RadioButton和Rad ...
- WPF 自定义柱状图 BarChart
WPF 自定义柱状图 当前的Telerik控件.DevExpress控件在图表控件方面做得不错,但是有时项目中需要特定的样式,不是只通过修改图表的模板和样式就能实现的. 或者说,通过修改当前的第三方控 ...
- wpf 自定义圆形按钮
wpf 自定义圆形按钮 效果图 默认样式 获取焦点样式 点击样式 下面是实现代码: 一个是自定义控件类,一个是控件类皮肤 using System; using System.Collections. ...
- WPF自定义窗口基类
WPF自定义窗口基类时,窗口基类只定义.cs文件,xaml文件不定义.继承自定义窗口的类xaml文件的根节点就不再是<Window>,而是自定义窗口类名(若自定义窗口与继承者不在同一个命名 ...
- WPF 自定义 MessageBox (相对完善版)
WPF 自定义 MessageBox (相对完善版) 基于WPF的自定义 MessageBox. 众所周知WPF界面美观.大多数WPF元素都可以简单的修改其样式,从而达到程序的风格统一.可是当 ...
- WPF自定义Window样式(2)
1. 引言 在上一篇中,介绍了如何建立自定义窗体.接下来,我们需要考虑将该自定义窗体基类放到类库中去,只有放到类库中,我们才能在其他地方去方便的引用该基类. 2. 创建类库 接上一篇的项目,先添加一个 ...
- WPF自定义Window样式(1)
1. 引言 WPF是制作界面的一大利器.最近在做一个项目,用的就是WPF.既然使用了WPF了,那么理所当然的,需要自定义窗体样式.所使用的代码是在网上查到的,遗憾的是,整理完毕后,再找那篇帖子却怎么也 ...
- WPF自学入门(九)WPF自定义窗口基类
今天简单记录一个知识点:WPF自定义窗口基类,常用winform的人知道,winform的窗体继承是很好用的,写一个基础窗体,直接在后台代码改写继承窗体名.但如果是WPF要继承窗体,我个人感觉没有理解 ...
随机推荐
- react 中的 setState
语法:setState(newState [,callback]) 1.只要有入门基础的同学都知道 setState({...}) 是更新组件中的 state 内容 2.但是,setState 是异步 ...
- Vim i和a差别
i是当前位置插入 a是当前文字的后面插入
- hdu 5361 2015多校联合训练赛#6 最短路
In Touch Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total ...
- 【bzoj4590】[Shoi2015]自动刷题机
因为解一定是单调的,n越小切的题越多,这是可以肯定的,那么直接二分答案 #include<algorithm> #include<iostream> #include<c ...
- Oracle 11g密码过期问题及解决方案
问题: 在自用的一个系统里,连接的是本地自建的一个数据库.用sqldeveloper登录数据库.提示如下图: 提示:密码过期 解决方案: 密码过期一般存在两种可能: 由于Oracle中默认在defau ...
- PL/SQL -->隐式游标(SQL%FOUND)
PL/SQL -->隐式游标(SQL%FOUND) 分类: SQL/PLSQL 基础2010-12-22 16:23 4084人阅读 评论(0) 收藏 举报 sqlexceptionoracle ...
- bzoj2705 [SDOI2012]Longge的问题——因数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2705 一开始自己想了半天... 有了点思路:遍历 n 的因数 k,每个因数要预处理出 gcd ...
- sql复杂查询语句总结
转自:http://blog.csdn.net/fengfeng91/article/details/15029173 create table student( sno varchar2(10) p ...
- 最短路径(Dijkstra算法)
当用图结构来表示通信.交通等网络,权重代表距离或者成本,寻找最短路径就成为了一个重要的任务. 给定带权网络G=(V;E),源点s,对于其他所有顶点v,寻找s到v的最短路径,连接成一颗最短路径树.可以证 ...
- PostgreSQL逻辑复制之pglogical篇
PostgreSQL逻辑复制之slony篇 一.pglogical介绍 pglogical 是 PostgreSQL 的拓展模块, 为 PostgreSQL 数据库提供了逻辑流复制发布和订阅的功能. ...