新建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. ps图片怎样实现渐变

    首先我先将一副图片展示给大家: 我所做的效果是想把图片做成渐变.而不改变中间图片的颜色效果. 接下来我来说明一下我的所做思路. 首先将图片中间部分选择出来.然后复制成一个图层. 详细操作是用魔棒进行反 ...

  2. SGU 261. Discrete Roots (N次剩余)

    N次剩余 题目:http://acm.sgu.ru/problem.php? contest=0&problem=261 题意:给定n,a,p 求出x^n ≡ a(mod p)在模p意义下的全 ...

  3. [RK3288][Android6.0] 调试笔记 --- Goodix GT9和GT9F区别【转】

    本文转载自:http://blog.csdn.net/kris_fei/article/details/78341425 Platform: RK3288 OS: Android 6.0 Kernel ...

  4. C# 函数的传值与传址(转)

    http://www.cnblogs.com/mdnx/archive/2012/09/04/2671060.html using System; using System.Collections.G ...

  5. python - 使用traceback获取详细的异常信息

    try: 1/0except Exception,e: print e 输出结果是integer division or modulo by zero,只知道是报了这个错,但是却不知道在哪个文件哪个函 ...

  6. uva10655

    Given the value of a+b and ab you will have to find the value of a n + b n Input The input file cont ...

  7. gitlab gerrit jenkins CI/CD环境集成

    http://blog.csdn.net/williamwanglei/article/details/38498465

  8. C++中正确使用PRId64 (转载)

    转自:http://blog.csdn.net/win_lin/article/details/7912693 例子参考高性能流媒体服务器SRS:https://github.com/winlinvi ...

  9. P4128 [SHOI2006]有色图

    传送门 数学渣渣看题解看得想死Ծ‸Ծ 首先发现这玩意儿看着很像polya定理 \[L=\frac{1}{|G|}\sum_{i\in G}m^{w(i)}\] 然而polya定理只能用来求点的置换,边 ...

  10. 基于.Net Core的API框架的搭建(3)

    5.加入缓存支持 我们希望为项目增加缓存支持,我们选择Redis做为缓存数据库. 首先,我们在Services目录增加一个缓存接口类ICacheService: using System; using ...