需求:
自定义RadioButton样式,作为切换页面的按钮
先上结果:
实现方式:
在自定义Style中,加入一个图标(阿里图库图标的使用),一个TextBlock文本,下方一个Border作为横线。
xmlns:helper="clr-namespace:Helper" //引用命名空间,放自定义属性的类的命名空间
<FontFamily x:Key="iconFamily">/你的项目名;component/Resources/#iconfont
</FontFamily> //iconFamily是图标文件(iconfont.ttf)的路径资源
<Style x:Key="MyRadionButtonIconAndText" TargetType="{x:Type RadioButton}">
<Setter Property="BorderBrush" Value="#635BDC"/>
<Setter Property="Foreground" Value="#99666666"/>
<Setter Property="Cursor" Value="Hand" />
<Setter Property="helper:MyIcon.IconText" Value=""/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid Background="{TemplateBinding Background}">
<Grid.ColumnDefinitions>