样式部分
<LinearGradientBrush x:Key="GradientBrush_1" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Offset="1" Color="#CEE5D1" />
<GradientStop Offset="0" Color="#FAFAFA" />
</LinearGradientBrush>
<Style TargetType="{x:Type RadioButton}" x:Key="rbut_style1">
<Setter Property="Width" Value="130" />
<Setter Property="Height" Value="60" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="FontSize" Value="24" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid x:Name="Ellipse" >
<Border x:Name="border1" >
<TextBlock x:Name="txt1" Text="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="False">
<Setter TargetName="border1" Property="Background" Value="#E2E2E2" />
<Setter TargetName="txt1" Property="Foreground" Value="#4E534F" />
<Setter TargetName="txt1" Property="FontWeight" Value="400" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="border1" Property="Background" Value="{StaticResource GradientBrush_1}" />
<Setter TargetName="border1" Property="BorderThickness" Value="0,0,0,5" />
<Setter TargetName="border1" Property="BorderBrush" Value="#43854B" />
<Setter TargetName="txt1" Property="Foreground" Value="#43854B" />
<Setter TargetName="txt1" Property="FontWeight" Value="Bold" />
</Trigger>
<DataTrigger Binding="{Binding CommandParameter, RelativeSource={RelativeSource Self}}" Value="0">
<Setter TargetName="border1" Property="CornerRadius" Value="5,0,0,5" />
</DataTrigger>
<DataTrigger Binding="{Binding CommandParameter, RelativeSource={RelativeSource Self}}" Value="2">
<Setter TargetName="border1" Property="CornerRadius" Value="0,5,5,0" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
xam
<RadioButton Content="长度" CommandParameter="0" Style="{StaticResource rbut_style1}" IsChecked="True"/>
<RadioButton Content="宽度" CommandParameter="1" Style="{StaticResource rbut_style1}" />
<RadioButton Content="高度" CommandParameter="2" Style="{StaticResource rbut_style1}" />
根据 CommandParameter 的value不同,背景圆角的方向不同
效果如
文章来源:https://www.toymoban.com/news/detail-601013.html
文章来源地址https://www.toymoban.com/news/detail-601013.html
到了这里,关于wpf RadioButton自定义样式 圆角/直角变化 背景色渐变的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!