新建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的更多相关文章

  1. wpf 自定义RadioButton控件样式

    实现的效果为: 我感觉来自定义RadioButton样式和定义button空间的样式差不多,只是类型不同而已. 接下来分析一下样式代码: <!--自定义单选按钮样式-->        & ...

  2. React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton)

    React Native之(支持iOS与Android)自定义单选按钮(RadioGroup,RadioButton) 一,需求与简单介绍 在开发项目时发现RN没有给提供RadioButton和Rad ...

  3. WPF 自定义柱状图 BarChart

    WPF 自定义柱状图 当前的Telerik控件.DevExpress控件在图表控件方面做得不错,但是有时项目中需要特定的样式,不是只通过修改图表的模板和样式就能实现的. 或者说,通过修改当前的第三方控 ...

  4. wpf 自定义圆形按钮

    wpf 自定义圆形按钮 效果图 默认样式 获取焦点样式 点击样式 下面是实现代码: 一个是自定义控件类,一个是控件类皮肤 using System; using System.Collections. ...

  5. WPF自定义窗口基类

    WPF自定义窗口基类时,窗口基类只定义.cs文件,xaml文件不定义.继承自定义窗口的类xaml文件的根节点就不再是<Window>,而是自定义窗口类名(若自定义窗口与继承者不在同一个命名 ...

  6. WPF 自定义 MessageBox (相对完善版)

    WPF 自定义 MessageBox (相对完善版)     基于WPF的自定义 MessageBox. 众所周知WPF界面美观.大多数WPF元素都可以简单的修改其样式,从而达到程序的风格统一.可是当 ...

  7. WPF自定义Window样式(2)

    1. 引言 在上一篇中,介绍了如何建立自定义窗体.接下来,我们需要考虑将该自定义窗体基类放到类库中去,只有放到类库中,我们才能在其他地方去方便的引用该基类. 2. 创建类库 接上一篇的项目,先添加一个 ...

  8. WPF自定义Window样式(1)

    1. 引言 WPF是制作界面的一大利器.最近在做一个项目,用的就是WPF.既然使用了WPF了,那么理所当然的,需要自定义窗体样式.所使用的代码是在网上查到的,遗憾的是,整理完毕后,再找那篇帖子却怎么也 ...

  9. WPF自学入门(九)WPF自定义窗口基类

    今天简单记录一个知识点:WPF自定义窗口基类,常用winform的人知道,winform的窗体继承是很好用的,写一个基础窗体,直接在后台代码改写继承窗体名.但如果是WPF要继承窗体,我个人感觉没有理解 ...

随机推荐

  1. 2014阿里巴巴WEB前端实习生在线笔试题

    2014年3月31日晚,我怀着稍微忐忑的心情(第一次在线笔试^_^!!)进行了笔试.阿里巴巴的笔试题共同拥有10道,差点儿包括了Web前端开发的各个方面,有程序题.有叙述题.时间很紧张,仅仅完毕了大概 ...

  2. 【OI】单调队列

    所谓单调队列,就是一个保持着某种性质的队列,通常是队列从队头到队尾,维护一种递增递减的关系. 这种队列通常用来解决一些连续区间的最值问题. 这种队列的入队要保证符合当前的性质,例如一个递增的单调序列( ...

  3. Delphi异常处理的基本原则和方法

    Delphi异常处理的基本原则和方法 一.异常的来源. 在Delphi的应用程序中,下列的情况都比较有可能产生异常.(1)文件处理(2)内存分配(3)Windows资源(4)运行时创建对象和窗体(5) ...

  4. java7中使用透明时与输入法冲突

    在Stackoverflow的这找到了答案,需要设置一下系统参数: static { System.setProperty("sun.java2d.noddraw", " ...

  5. YTU 2629: E1 一种颜色,三个分量

    2629: E1 一种颜色,三个分量 时间限制: 1 Sec  内存限制: 128 MB 提交: 300  解决: 226 题目描述 在计算机中,常用三种基色红(R).绿(G).蓝(B)的混合来表示颜 ...

  6. 【CEOI2002】【Poj 1038】Bugs Integrated, Inc.

    http://poj.org/problem?id=1038 发一下中文题面(今天考试直接被改了): 生记茶餐厅由于受杀人事件的影响,生意日渐冷清,不得不暂时歇业.四喜赋闲在家,整天抱着零食看电视,在 ...

  7. Varnish的VCL

    Varnish的子进程 VCL Varnish配置语言VCL是一种"域"专有类型的配置语言,用于描述Varnish Cache的请求处理和文档高速缓存策略. 当加载新配置时,Man ...

  8. easyui-filebox 文件上传

    参考文章:http://blog.csdn.net/fsdad/article/details/73200618 easyui论坛:http://www.jeasyui.com/forum/index ...

  9. TCP/IP的排头兵――地址解析协议(ARP) (转载)

    转自:http://blog.csdn.net/wangxg_7520/article/details/2488442 一.引言 古人行军打仗,都要有一个可以引领队伍前进方向的排头兵,在TCP/IP网 ...

  10. 【WIP_S3】链表

    创建: 2017/12/26 完成: 2018/01/14   [TODO]     S4, S5, S14来处理动态数组   CAF8A81B790F [github 地址]传送门  链表的定义   ...